Перейти к содержанию

Python complex() built-in function

Python complex() built-in function

From the Python 3 documentation Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j.

Examples

>>> complex(1)
# (1+0j)
>>> complex('1')
# (1+0j)
>>> complex(100)
# (100+0j)
>>> complex('100')
# (100+0j)