How to use isfinite() to check if regular numbers or special values inf or nan in Python

1 Answer

0 votes
import math       

for f in [0.0, 1.0, math.e, math.pi, math.nan, math.inf]:           
    print('{:4.2f} {!s}'.format(f, math.isfinite(f)))


'''
run:

0.00 True
1.00 True
2.72 True
3.14 True
 nan False
 inf False

'''

 



answered Jun 29, 2019 by avibootz
edited Jun 29, 2019 by avibootz
...