Complex
#
- class examples.samples.Complex(real, imag=0.0)#
Bases:
object
Custom implementation of a complex number.
- Parameters:
Examples
>>> my_num = Complex(real=1, imag=-1.0) >>> my_num (1.0 + 1.0j)
Overview#
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__()#