complex()

christian.dinh2481 total contributions
Published Jul 6, 2021Updated Aug 7, 2023
Contribute to Docs
The complex()
function converts a given string, or pair of numbers, into a complex number.
Syntax
result1 = complex(real, imaginary)
result2 = complex(string)
real
is the real part of a complex number.imaginary
is the imaginary part of a complex number.string
is the string representation of a complex number.
Example
Use complex()
to convert the string "1+7j"
into a complex number:
num = complex("1+7j")print(num)
This will result in the following output:
(1+7j)
Note: The passed string cannot contain whitespaces. A string such as,
"1 + 7j"
, will result in an error.
Codebyte Example
Use complex()
to convert the string "1.5"
which is passed as a single parameter, into a complex number:
All contributors
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor194 total contributions
- Anonymous contributorAnonymous contributor2 total contributions
- christian.dinh
- Anonymous contributor
- Anonymous contributor
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.