all Python 3numbersterm
numbers.Complex
numeric tower
The abstract class of complex numbers: addition, multiplication, real, imag, conjugate(). complex, float and int belong here.
Syntax
isinstance(x, numbers.Complex)
Complex does not require < and > ordering: complex has none, so code that sorts "numbers" should test for Real, not Complex. float and int are Complex too: they have .real, .imag and conjugate(). Decimal is not here, although it is a Number: it does not mix with float and complex in arithmetic.
Examples
import numbers
from decimal import Decimal
print(isinstance(1j, numbers.Complex), isinstance(2.5, numbers.Complex)) # → True True
print(isinstance(1j, numbers.Real), isinstance(Decimal('1'), numbers.Complex)) # → False False
print((3).imag, (2.5).conjugate()) # → 0 2.5
See also
Open in the full glossarydocs.python.orgReport an inaccuracy