Python Tutorial Python Advanced Python References Python Libraries

Python cmath - isfinite() Function



The Python cmath.isfinite() function returns True if both the real and imaginary parts of a given complex number are finite, and False otherwise.

Syntax

cmath.isfinite(x)   

Parameters

x Required. Specify the value.

Return Value

Returns true if both the real and imaginary parts of the argument are finite, and false otherwise.

Example:

In the example below, isfinite() function is used to check if the argument is a finite number or not.

import cmath

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

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

The output of the above code will be:

True
True
True

False
False
False

❮ Python cMath Module