Python – How to check for NaN values

mathpython

float('nan') results in Nan (not a number). But how do I check for it? Should be very easy, but I cannot find it.

Best Solution

math.isnan(x)

Return True if x is a NaN (not a number), and False otherwise.

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True