Home » Python

math.isnan() method with example in Python

Python math.isnan() method: Here, we are going to learn about the math.isnan() method with example in Python.
Submitted by IncludeHelp, on April 18, 2019

Python math.isnan() method

math.isnan() method is a library method of math module, it is used to check whether a given number is "NaN" (Not a Number) or not, it accepts a number and returns True if given number is "NaN", else it returns False.

Syntax of math.isnan() method:

    math.isnan(n)

Parameter(s): n – a number that has to be checked whether it is "NaN" or not.

Return value: bool – it returns a Boolean ("True" or "False") value.

Example:

    Input:
    a = 10
    b = float('inf')
    c = float('nan')

    # function call
    print(math.isnan(a))
    print(math.isnan(b))
    print(math.isnan(c))

    Output:
    False
    False
    True

Python code to demonstrate example of math.isnan() method

# python code to demonstrate example of 
# math.isnan() method

# importing math module
import math

# math.isnan() method test on finite value
print(math.isnan(10))
print(math.isnan(0))
print(math.isnan(10.23))
print(math.isnan(0.0))


# math.isnan() method test on infinite and NaN value
print(math.isnan(float('inf')))
print(math.isnan(float('-inf')))
print(math.isnan(float('nan')))

Output

False
False
False
False
False
True





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.