Skip to content

Instantly share code, notes, and snippets.

@funkycoder
Last active December 5, 2020 15:22
Show Gist options
  • Save funkycoder/c0304be0438975d641509233181ed99a to your computer and use it in GitHub Desktop.
Save funkycoder/c0304be0438975d641509233181ed99a to your computer and use it in GitHub Desktop.
NaN and Inf in Python
#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