`float('nan')`

results Nan (not a number). It is very easy but how can I check?

Login

+2 votes

You can use math.isnan() which will return True if the variable is a NAN else False

Syntax-

math.isnan(variable)

Alternatively, another way to test for NaN is comparing the number to itself.

def isNaN(num):

return num != num