Python Glossary Русский

Python 3.2+cmathfunction

cmath.isfinite()

checking

Checks that both parts of a complex number are finite, neither infinity nor NaN.

Syntax

cmath.isfinite(z)

A number counts as finite only when both the real and the imaginary parts are finite: complex(1, inf) is not finite, although its main part is 1. It is not the opposite of isinf: NaN is neither finite nor infinite, so for complex(nan, 0) both checks give False.

Examples

import cmath
print(cmath.isfinite(1 + 2j), cmath.isfinite(complex(1, float('inf'))))  # → True False
z = complex(float('nan'), 0)
print(cmath.isfinite(z), cmath.isinf(z))  # → False False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy