Python Glossary Русский

Python 3.6+cmathterm

cmath.nan

constants

The NaN (not a number) value in the cmath module: float('nan'), the same value as math.nan.

Syntax

cmath.nan

NaN equals nothing, itself included: cmath.nan == cmath.nan is False, and so is cmath.nan == math.nan. So a check x == cmath.nan never works; use cmath.isnan or math.isnan. It is a float, and there is nanj for NaN in the imaginary part.

Examples

import cmath
x = cmath.nan
print(x == x, cmath.isnan(x))  # → False True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy