CKTIS / Python
complex()
Builds a complex number from real and imaginary components or parses a complex literal string.
Version: Python 3.14; repository image, production runtime not attested
Syntax
complex(number=0, /)
complex(real=0, imag=0)Builds a complex number from real and imaginary components or parses a complex literal string.
Adding an imaginary component separately combines two real inputs; the single-string form parses both components together.
A single numeric argument converts to complex. In Python 3.14, passing complex numbers as real or imag in the two-component form emits DeprecationWarning. With two real components, the first sets the real part and the second the imaginary coefficient, giving 3−2j. The single-string form parses both parts together. Supplying a string and a separate imaginary argument raises TypeError. The resulting real and imaginary components are floats.
assert complex(3) == 3+0j and complex(3-2j) == 3-2j
assert complex() == 0j and complex(3, -2) == 3 - 2j
assert complex("3-2j").imag == -2.0
Examples
print(complex(3, -2))
print(complex("3-2j") == complex(3, -2))
Result
(3-2j) True
A single numeric argument converts to complex. In Python 3.14, passing complex numbers as real or imag in the two-component form emits DeprecationWarning. With two real components, the first sets the real part and the second the imaginary coefficient, giving 3−2j. The single-string form parses both parts together. Supplying a string and a separate imaginary argument raises TypeError. The resulting real and imaginary components are floats.