Python Complex Numbers

by Atakan

Basically, it takes 2 parameters on complex numbers. In standard use. The real (i) and imaginary (j) part.

Let’s look at a topic like this, if we say a + bj in general
part a shows the real number
b is the imaginary part
j is the value of the imaginary part as a unit
One of the parts that we should pay attention to here is that j does not come first and b is put at the end.

my_comp_no1 = 10 + 50j
print(my_comp_no1)  #(10+50j)

my_comp_no2 = 10 + j50
print(my_comp_no2)  #NameError: name 'j50' is not defined

How can we take the real and imaginary part of the complex number one by one? we can use it as .real and .imag for this.

my_comp_no1 = 10 + 50j
print("real" , my_comp_no1.real)    #real 10.0
print("imagine" , my_comp_no1.imag) #imagine 50.0

Python allows us to perform arithmetic between each other with complex number variables

my_comp_no1 = 20 + 50j
my_comp_no2 = 10 + 10j
print(my_comp_no1 * my_comp_no2)    #(-300+700j)
print(my_comp_no1 + my_comp_no2)    #(30+60j)
print(my_comp_no1 - my_comp_no2)    #(10+40j)

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. OK Read More