NaN variable without NumPy

0 votes
A NaN constant is used in most of the languages in order to assign a variable the NaN value. Is it possible to do the same in Python without using NumPy?
Nov 26, 2018 in Python by ana1504.k
• 7,910 points
1,934 views

1 answer to this question.

0 votes
Yes, It is possible to use the NaN variable without NumPy in Python.

You can use float('nan') for the following.  In Python 3.5, you can also use math.nan.

>>> a = float('nan')
>>> print(a)
nan
>>> print(a + 2)
nan
>>> a == a
False
>>> import math
>>> math.isnan(a)
True
>>> # Python 3.5+
>>> math.isnan(math.nan)
True
answered Nov 26, 2018 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

Declare variable without assigning any value in Python?

var = None Python is dynamic, so you ...READ MORE

answered Oct 29, 2018 in Python by Priyaj
• 58,020 points
3,681 views
0 votes
1 answer

How to pretty-print a numpy.array without scientific notation and with given precision?

Hii @kartik, The numpy arrays have the method round(precision) which ...READ MORE

answered Apr 14, 2020 in Python by Niroj
• 82,840 points
3,094 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
1,035 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,434 views
0 votes
1 answer
0 votes
1 answer

How to use a global variable in function?

The global variable can be used in ...READ MORE

answered Sep 27, 2018 in Python by SDeb
• 13,300 points
921 views
0 votes
1 answer

How to exit from Python without traceback?

You are presumably encountering an exception and ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,300 points
1,094 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