Python 3.6+cmathterm
cmath.nanj
constants
A complex number with a zero real part and NaN as the imaginary part, complex(0.0, nan).
Syntax
cmath.nanj
The real part of nanj is an honest 0.0, but the number as a whole counts as NaN: cmath.isnan(nanj) is True and nanj == nanj is False. A check of z.real alone lets such a value through; look at both parts or call cmath.isnan.
Examples
import cmath
z = cmath.nanj
print(z, z.real) # → nanj 0.0
print(cmath.isnan(z), z == z) # → True False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy