Python Tutorial Python Advanced Python References Python Libraries

Python cmath - isnan() Function



The Python cmath.isnan() function returns 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 example below, 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),"\n")

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