+ 2

how does the python interpreter assess a=b?

does a=b mean that the value of b is now value of a OR the value of a is now the value of b ? is the reading order of the interpreter from the right to left or from left to right? for ex we have to swap two variables using a third one let's say a=90 b=10 and assume c as the third variable if the reading order is right to left then c=a means the value of a is now equal to c ....going by the same convention the code for swapping will be c=a b=a c=b but when I execute this both variables's value is same Can somebody please explain this to me ?

4th Aug 2018, 6:16 PM
shaleen agarwal
shaleen agarwal - avatar
4 Antworten
+ 4
a = 1 b = 2 a = b print(a) #output is 2 c = a b = a c = b print(c) #output is 2
4th Aug 2018, 6:20 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 3
hi shaleen agarwal,i hope that you have nice time,in each language when you want to swap two variable for example A=20 and B=23 ,you need the third variable for example C "Just as you said". i want to say when you put it equal two variable in each language you should look at the code from right to left. lets look at this code: C=A; //form right to left fist C equal to A,"i mean at first A was 20 and when you put it equal A with C, C be 20" A=B;//form right to left fist B equal to A,"i mean at first B was 23 and when you put it equal B with A, A be 23" B=C;//form right to left fist C equal to B,"i mean at first C was 20 and when you put it equal C with B, B be 20" by this code you swap two variable i hope to help you,good luck
4th Aug 2018, 6:39 PM
Amirhossein Mohammadi
Amirhossein Mohammadi - avatar
+ 2
hi. The assignment operator (a = b) initializes or updates the value of a with the value of b
5th Aug 2018, 7:52 AM
Amirhossein Mohammadi
Amirhossein Mohammadi - avatar
+ 1
a=b means that the value of b has been assigned to a
4th Aug 2018, 6:19 PM
TheNewHEROBRINE
TheNewHEROBRINE - avatar