Built-in Functions and Types

complex()

Build a complex value from one number, from complex-number text, or from two numeric components. Python uses j for the imaginary unit. Text is a single argument, with no whitespace inside the numeric expression; invalid text raises ValueError. The two-argument form combines real + imag * 1j. Complex values do not support ordinary magnitude ordering with < or >.

Formal Syntax & Structure

python syntaxpython
complex(number=0, /)complex(string, /)complex(real=0, imag=0)

Parameters & Attributes

NameTypeDescription
numbernumber or conversion-protocol objectSingle-number form; default zero.
stringstrSingle text argument, without an imaginary argument.
realnumberReal component in the component form; default zero.
imagnumberImaginary component; default zero.

Return Value

complex

Complex number with floating-point real and imaginary components.

Working Example

Example Snippetpython
signal = complex(6, -8)print(signal.real, signal.imag)print(abs(signal))
Python Reference