Explore Courses Blog Tutorials Interview Questions
+1 vote
in Python by (200 points)

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

1 Answer

+2 votes
by (10.9k points)
edited by

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



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

def isNaN(num):

   return num != num

Related questions

0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)
+1 vote
1 answer
asked Jul 31, 2019 in Python by Aarav (11.4k points)
0 votes
1 answer

Browse Categories