Python Tutorial Python Advanced Python References Python Libraries

Python cmath - isinf() Function



The Python cmath.isinf() function returns True if either the real or the imaginary part of a given complex number is an infinity, and False otherwise.

Syntax

cmath.isinf(x)   

Parameters

x Required. Specify the value.

Return Value

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

Example:

The example below shows the usage of isinf() function.

import cmath

print(cmath.isinf(2 + 2j))
print(cmath.isinf(-2))
print(cmath.isinf(1.5j),"\n")

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

The output of the above code will be:

False
False
False

False
True
True

❮ Python cMath Module