Open In App
Related Articles

Python math library | isnan() method

Improve Article
Improve
Save Article
Save
Like Article
Like

Python has math library and has many functions regarding it. One such function is isnan(). This method is used to check whether a given parameter is a valid number or not.

Syntax : math.isnan(x) Parameters : x [Required] : It is any valid python data type or any number. Returns: Return type is boolean. -> Returns False if the given parameter is any number(positive or negative) -> Returns True if given parameter is NaN (Not a Number).

Time Complexity: O(1)

Auxiliary Space: O(1)

Code #1: 

python3




# Python3 code to demonstrate
# the working of isnan()
import math
 
# initializing the value
test_int = 4
test_neg_int = -3
test_float = 0.00
 
# checking isnan() values
# with different numbers
print (math.isnan(test_int))
print (math.isnan(test_neg_int))
print (math.isnan(test_float))


Output:

False
False
False

  Code #2: 

python3




# Python3 code to demonstrate
# the working of isnan()
import math
 
# checking isnan() values
# with inbuilt numbers
print (math.isnan(math.pi))
print (math.isnan(math.e))
 
 
# checking for NaN value
print (math.isnan(float('nan')))


Output:

False
False
True
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 20 Feb, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials