Use abs(z) to get its magnitude (as a float) or z.real to get its real part. : Complex Numbers « Data Type « Python






Use abs(z) to get its magnitude (as a float) or z.real to get its real part.

Use abs(z) to get its magnitude (as a float) or z.real to get its real part.

#The conversion functions to floating point and integer 
#(float(), int() and long()) don't work for complex numbers 


a=3.0+4.0j

print a.real

print a.imag

print abs(a)  # sqrt(a.real**2 + a.imag**2)


           
       








Related examples in the same category

1.Complex Numbers: MultiplyComplex Numbers: Multiply
2.Complex Number Multiply: the Complex partComplex Number Multiply: the Complex part
3.Complex Numbers: two complex numbersComplex Numbers: two complex numbers
4.Complex numbers: imaginary numbers are written with a suffix of 'j' or 'J'. Complex numbers: imaginary numbers are written with a suffix of 'j' or 'J'.
5.Complex numbers: represented as two floating point numbersComplex numbers: represented as two floating point numbers