Python math.isnan() Method
Python math.isnan()The method determines whether a number is NaN (not a number). If the number is NaN (not a number), it returns True, otherwise it returns False.
Python version: 3.5
Syntax
The syntax of the math.isnan() method is as follows:
math.isnan(x)
Parameter description:
- x-- Required, number. If x is not a number, returns TypeError.
Return Value
Returns a boolean value. Returns True if the number is NaN (not a number), otherwise returns False.
Examples
The following example checks whether a number is NaN (not a number:
Examples
# Import the math package
import math
# Check whether the number is NaN
print (math.isnan (56))
print (math.isnan (-45.34))
print (math.isnan (+45.34))
print (math.isnan (math.inf))
print (math.isnan (float("nan")))
print (math.isnan (float("inf")))
print (math.isnan (float("-inf")))
print (math.isnan (math.nan))
import math
# Check whether the number is NaN
print (math.isnan (56))
print (math.isnan (-45.34))
print (math.isnan (+45.34))
print (math.isnan (math.inf))
print (math.isnan (float("nan")))
print (math.isnan (float("inf")))
print (math.isnan (float("-inf")))
print (math.isnan (math.nan))
Output:
False False False False True False False TrueOther Extensions
Python math Module