Python complex() Function
Example
Convert the numbers 7 and the imaginary number 8 to a complex number:
x = complex(7, 8)
Definition and Usage
The complex() function returns a complex number by specifying the real number and the imaginary number.
Syntax
complex(Real, Imaginary)
Parameter Value
Parameter | Description |
---|---|
Real |
Required. Represents the number of the real part of the complex number. The default value is 0. The real number can also be a string, such as '3+5j'. In this case, the second parameter should be omitted. |
Imaginary | Optional. Represents the imaginary part of the complex number. The default value is 0. |