+ 2
Python
a = 5 b = 7 c=b=a print(b) Can anyone explain whats happening there and why b value is 5 but not 7 ?
3 Answers
+ 8
Ramana Sai
See the thing is
The value of a is 5
The value of b is 7
The value of c is first assigned to the value of b that is 7 ok?
After that again the value of b is assigned to a that is 5 that's the only reason the answer is 5
Lemme explain you in more comfortable language.
A=5
B=7
C=b (which is 7)=a(now the value of b is changed to the value of a which is 5)
So the answer is 5
Thanks
Hope this helps đ€
+ 2
It is so simple.Firstly assign c to b so c = 7 b = 7 then assign b to a will gives b = 5.
In summary:
c = b = a => b = a (5) and c = b (5)
+ 1
REASON
Assignment operator (=) has right to left Associativity.
DHANANJAY PATEL