Skip to main content

complex

Complex

>>> dir(complex)
['__abs__', '__add__', '__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__pow__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', 'conjugate', 'imag', 'real']

Dunder methods

Dunder MethodOperationExample (normal syntax)Example (dunder call)
__add__Addition(2+3j) + (1+4j)(3+7j)(2+3j).__add__(1+4j)
__sub__Subtraction(5+2j) - (3+1j)(2+1j)(5+2j).__sub__(3+1j)
__mul__Multiplication(2+3j)*(1+2j)(-4+7j)(2+3j).__mul__(1+2j)
__truediv__Division(1+2j)/(1+1j)(1.5+0.5j)(1+2j).__truediv__(1+1j)
__abs__Magnitudeabs(3+4j)5.0(3+4j).__abs__()
__eq__Equality(1+2j) == (1+2j)True(1+2j).__eq__(1+2j)
__neg__Negation-(3+4j)(-3-4j)(3+4j).__neg__()
__complex__Convert to complexcomplex(3)(3+0j)(3).__complex__()