complex()
returns an expression or object converted into a complex number.
CASE I
complex(real, imaginary)
CASE II
complex(string)
Here, in CASE I:
In CASE II:
Note: The string must not contain whitespace around the central + or - operator while converting from a string. For eg.
complex(’2+5j’) is correct, while complex(’2 + 5j’) raises *ValueError
.*
Also if the first parameter(real part) is a string, it will be represented as a complex number, and the second parameter must be omitted.
>>> complex()
0j
>>> complex(1)
(1+0j)
>>> complex(1, 2)
(1+2j)
>>> complex(1.12, 2.34)
(1.12+2.34j)
>>> complex(1, 2.34)
(1+2.34j)
>>> complex(1+2j)
(1+2j)
>>> complex(1+2j, 3+4j)
(-3+5j)
>>> complex('1')
(1+0j)
>>> complex('1+5j')
(1+5j)