pythonmathnan

How to check for NaN values


float('nan') represents NaN (not a number). But how do I check for it?


Solution

  • Use math.isnan:

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