Looking for python Answers? Try Ask4KnowledgeBase
Looking for python Keywords? Try Ask4Keywords

Python Language Basic complex arithmetic


Python has built-in support for complex arithmetic. The imaginary unit is denoted by j:

z = 2+3j # A complex number
w = 1-7j # Another complex number

Complex numbers can be summed, subtracted, multiplied, divided and exponentiated:

z + w # (3-4j) 
z - w # (1+10j)
z * w # (23-11j) 
z / w # (-0.38+0.34j)
z**3  # (-46+9j)

Python can also extract the real and imaginary parts of complex numbers, and calculate their absolute value and conjugate:

z.real # 2.0
z.imag # 3.0
abs(z) # 3.605551275463989
z.conjugate() # (2-3j)