On this page
complex
Prev: compile | Up: __builtins__ | Next: copyright
Rel: bool, int, float, str, bytes
Ref: docs.python.org — complex
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import complex
Overview & Signature
complex(real=0, imag=0)
Create a complex number from a string or numbers.
Common Methods & Attributes
complex.conjugate(self, /)— Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.complex.from_number(number, /)— Convert number to a complex floating-point number.complex.imag(...)— the imaginary part of a complex numbercomplex.real(...)— the real part of a complex number
Usage
z = complex(3, 4)
assert z == (3 + 4j) and z.real == 3.0 and z.imag == 4.0 and abs(z) == 5.0
assert z.conjugate() == (3 - 4j)
Gotchas
- No spaces around
+/-when parsing strings:complex("3+4j")works,complex("3 + 4j")raisesValueError. - No ordering (
<,>): Complex numbers raiseTypeErroron inequality comparisons.
REPL Inspect
help(complex)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/bool
- tuts/python3/__builtins__/bytearray
- tuts/python3/__builtins__/bytes
- tuts/python3/__builtins__/compile
- tuts/python3/__builtins__/copyright
- tuts/python3/__builtins__/dict
- tuts/python3/__builtins__/float
- tuts/python3/__builtins__/frozenset
- tuts/python3/__builtins__/int
- tuts/python3/__builtins__/list
- tuts/python3/__builtins__/memoryview
- tuts/python3/__builtins__/object
- tuts/python3/__builtins__/range
- tuts/python3/__builtins__/set
- tuts/python3/__builtins__/slice
- tuts/python3/__builtins__/str
- tuts/python3/__builtins__/tuple
- tuts/python3/__builtins__/type
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bool Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bytes Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/compile Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/copyright Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/float Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/int Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/str Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bytearray links to this page; shared tags: #builtins