Complex#

class examples.samples.Complex(real, imag=0.0)#

Bases: object

Custom implementation of a complex number.

Parameters:
realfloat

Real component of the complex number.

imagfloat, optional

Imaginary component of the complex number.

Examples

>>> my_num = Complex(real=1, imag=-1.0)
>>> my_num
(1.0 + 1.0j)

Overview#

real

Real component of this complex number.

imag

Real component of this complex number.

abs

Return the absolute value of this number.

__add__

Add two complex numbers.

__sub__

Subtract two complex numbers.

__mul__

Multiply two complex numbers.

__truediv__

Divide two complex numbers.

__repr__

Import detail#

from examples.samples import Complex

Property detail#

property Complex.real#

Real component of this complex number.

Examples

>>> my_num = Complex(real=1, imag=-1.0)
>>> my_num.real
1.0
property Complex.imag#

Real component of this complex number.

Examples

>>> my_num = Complex(real=1, imag=-1.0)
>>> my_num.imag
-1.0

Set the imaginary component

>>> my_num.imag = 2.0
>>> my_num.imag
2.0
property Complex.abs#

Return the absolute value of this number.

Examples

>>> my_num = Complex(real=1, imag=1.0)
>>> my_num.abs

Method detail#

Complex.__add__(other)#

Add two complex numbers.

Complex.__sub__(other)#

Subtract two complex numbers.

Complex.__mul__(other)#

Multiply two complex numbers.

Complex.__truediv__(other)#

Divide two complex numbers.

Complex.__repr__()#