Last active
December 5, 2020 15:22
-
-
Save funkycoder/c0304be0438975d641509233181ed99a to your computer and use it in GitHub Desktop.
NaN and Inf in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Q: How do you represent NaN of Inf in Python? | |
#A: Call float(x) with x as either the string "NaN" or "Inf" to create a NaN or Inf value. | |
nan = float('NaN') | |
inf = float('Inf') | |
#Q: How to check NaN of Inf value | |
#A: math.isnan(x), math.isinf(x) | |
import math | |
math.isnan(nan) | |
>>> True | |
math.isnan(inf) | |
>>> False | |
math.isinf(inf) | |
>>> True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment