Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python cmath.isnan() function is used to return True if either the real or the imaginary part of a given complex number is a NaN, and False otherwise.

Syntax

cmath.isnan(x)   

Parameters

x Required. Specify the value.

Return Value

Returns true if either the real or the imaginary part of the argument is a NaN, and false otherwise.

Example:

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

import cmath

print(cmath.isnan(2 + 2j))
print(cmath.isnan(-2))
print(cmath.isnan(1.5j))

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

The output of the above code will be:

False
False
False

False
False
True

❮ Python cMath Module