complex()

Converts a given string into a complex number.

Syntax

complex(real, imaginary)

Example 1

Use complex() to convert the string "1+7j" into a complex number:

num = complex("1+7j")
print(num)

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors