Python Tutorial Python Advanced Python References Python Libraries

Python math - isnan() Function



The Python math.isnan() function is used to check if the argument is a NaN (not a number). It returns true if the argument is a NaN, else returns false.

Syntax

math.isnan(x)   

Parameters

x Required. Specify the value.

Return Value

Returns true if the argument is a NaN, else returns false.

Example:

In the example below, isnan() function is used to check if the argument is a NaN or not.

import math

print(math.isnan(2))
print(math.isnan(-2))
print(math.isnan(1.5),"\n")

print(math.isnan(float("inf")))
print(math.isnan(float("-inf")))
print(math.isnan(float("nan")))

The output of the above code will be:

False
False
False

False
False
True

❮ Python Math Module