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
| Name | Type | Description |
|---|---|---|
| number | number or conversion-protocol object | Single-number form; default zero. |
| string | str | Single text argument, without an imaginary argument. |
| real | number | Real component in the component form; default zero. |
| imag | number | Imaginary 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))