Easy Tutorial
❮ Python Os Rename Python Att List Count ❯

Python math.isnan() Method

Python math Module

The math.isnan() method in Python checks if a number is NaN (Not a Number). It returns True if the number is NaN, otherwise it returns False.

Python Version: 3.5

Syntax

The syntax for the math.isnan() method is as follows:

math.isnan(x)

Parameter:

Return Value

Returns a boolean value. True if the number is NaN, otherwise False.

Example

The following example checks if a number is NaN:

Example

# Import math package
import math

# Check if 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
True

Python math Module

❮ Python Os Rename Python Att List Count ❯