Python math.isnan() Method
Python math.isnan() The method determines whether a number is NaN (not a number), returning True if the number is NaN, otherwise False.
Python version: 3.5
Syntax
The syntax of the math.isnan() method is as follows:
math.isnan(x)
Parameter Description:
- x -- required, a number. If x is not a number, a TypeError is returned.
Return Value
Returns a Boolean; True if the number is NaN (not a number), otherwise False.
Example
The following example checks whether a number is NaN (not a number:
Example
Import the math package
import
math
Check whether a number is NaN
(
math
.
isnan
(
56
)
)
(
math
.
isnan
(
45.34
)
)
(
math
.
isnan
(
45.34
)
)
(
math
.
isnan
(
math
.
inf
)
)
(
math
.
isnan
(
float
(
"nan"
)
)
)
(
math
.
isnan
(
float
(
"inf"
)
)
)
(
math
.
isnan
(
float
(
"-inf"
)
)
)
(
math
.
isnan
(
math
.
nan
)
)
Output result:
False
False
False
False
True
False
False
True
Python math Module