Python Language Complex math Basic complex arithmetic

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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)


Got any Python Language Question?