cmath
Complex-number arithmetic implemented in Python. Construct values with
complex(real, imag=0) or imaginary literals such as 2j.
import cmath
value = complex(3, 4)
assert value.real == 3.0
assert value.imag == 4.0
assert value.conjugate() == complex(3, -4)
assert cmath.isclose(cmath.sqrt(complex(-1, 0)), complex(0, 1))
radius, angle = cmath.polar(value)
assert cmath.isclose(cmath.rect(radius, angle), value)
Pass complex values explicitly to functions that access real and imag.
isclose checks the real and imaginary parts with math.isclose;
it does not accept CPython's tolerance keywords. Do not assume identical
branch-cut or domain-error behavior for all inputs.
Implementation: cmath.py.