THE WORLD'S LARGEST WEB DEVELOPER SITE

Python complex() Function

❮ Built-in Functions


Example

Convert the number 3 and imaginary number 5 into a complex number:

x = complex(3, 5)
Run example »

Definition and Usage

The complex() function returns a complex number by specifying a real number and an imaginary number.


Syntax

complex(real, imaginary)

Parameter Values

Parameter Description
real Required. A number representing the real part of the complex number. Default 0. The real number can also be a String, like this '3+5j', when this is the case, the second parameter should be omitted.
imaginary Optional. A number representing the imaginary part of the complex number. Default 0.

More Examples

Example

Convert a string into a complex number:

x = complex('3+5j')
Run example »

❮ Built-in Functions