How can I check for NaN in Python

0 votes

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

Aug 16, 2018 in Python by bug_seeker
• 15,520 points
24,113 views

1 answer to this question.

0 votes

math.isnan()

Checks if the float x is a NaN (not a number). NaNs are part of the IEEE 754 standards. Operation like but not limited to inf * 0, inf / inf or any operation involving a NaN, e.g. nan * 1, return a NaN.

New in version 2.6.

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

Hope this helps!!

If you need to learn more about Python, It's recommended to join Python Programming course today.

Thanks!

answered Aug 16, 2018 by Priyaj
• 58,100 points

Related Questions In Python

0 votes
1 answer

how do i check for exceptions in python?

use self.assertRaises method as a context manager. def ...READ MORE

answered Mar 12, 2019 in Python by Mohammad
• 3,230 points
622 views
0 votes
1 answer

How can I deal with python eggs for multiple platforms in one location?

Try virtualenv : http://pypi.python.org/pypi/virtualenv This helps you create isolated ...READ MORE

answered May 28, 2019 in Python by SDeb
• 13,300 points
878 views
0 votes
1 answer

How can I change the iteration variable inside a for loop in python?

Assume you have a list of lists: my_list ...READ MORE

answered Jun 10, 2019 in Python by Shubham Bansal
5,624 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,363 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,934 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
13,469 views
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 58,100 points
3,482 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP