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,590 points
55 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
• 12,600 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
• 56,160 points
31 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
43 views
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
16,773 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 136 views
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
• 12,600 points
17 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
• 12,600 points
53 views