PyDocs

Nav

Python Runtime Services

complex

builtins

classDeprecated 3.14
  • complex(number=0, /)
  • complex(string, /)
  • complex(real=0, imag=0)
Deprecated since 3.14. Passing a complex number as the real or imag argument is now deprecated; it should only be passed as a single positional argument.
Create a complex number from a string or numbers.

If a string is given, parse it as a complex number.
If a single number is given, convert it to a complex number.
If the 'real' or 'imag' arguments are given, create a complex number
with the specified real and imaginary components.
Changed in 3.6, 3.8
  • 3.6: Grouping digits with underscores as in code literals is allowed.
  • 3.8: Falls back to __index__() if __complex__() and __float__() are not defined.
Members of complex

f

from_number
Convert number to a complex floating-point number.
1 Example
>>> complex('+1.23')
(1.23+0j)
>>> complex('-4.5j')
-4.5j
>>> complex('-1.23+4.5j')
(-1.23+4.5j)
>>> complex('\t( -1.23+4.5J )\n')
(-1.23+4.5j)
>>> complex('-Infinity+NaNj')
(-inf+nanj)
>>> complex(1.23)
(1.23+0j)
>>> complex(imag=-4.5)
-4.5j
>>> complex(-1.23, 4.5)
(-1.23+4.5j)
from the Python docs
See Also
No see-alsos for builtins/complex
0 Notes
No notes for complex