How can I check for NaN values?

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

1
18

Use math.isnan:

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

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

Leave a Comment