float('nan')
represents NaN (not a number). But how do I check for it?
1
Use math.isnan
:
Return
True
if x is a NaN (not a number), andFalse
otherwise.
>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True