+ 2

a=5 b=a a=4 print(b) What is output and why :)

21st Sep 2016, 4:59 PM
Andrew Arugula
Andrew Arugula - avatar
10 ответов
+ 9
the output will be 5 because the value of b was assigned then after the value of a is changed so the value of b not change
21st Sep 2016, 6:52 PM
shashank
shashank - avatar
+ 4
The output will be: 5 since, value of a(5) is assigned to b. after assigning b the value of a is changed so it will not be updated in b.
21st Sep 2016, 5:05 PM
Rasool Khan.M
Rasool Khan.M - avatar
+ 2
значение из переменной справа от равно, уходит в переменную слева от равно) т.е. слева от равно стоит приёмник значения
21st Sep 2016, 6:36 PM
Alexey Vedernikov
Alexey Vedernikov - avatar
+ 2
answer will be 5 because before assigning a new value to a the older value was stored in b.The program executes from top to bottom.
26th Sep 2016, 2:43 PM
nitesh pandey
nitesh pandey - avatar
+ 2
The output will be 5 Simply, it's like first "a" becomes 5, then "b" becomes "a" ie "b" now becomes 5. Nothing is said about "b", so" b"remains "b". Next part of the story is" a" becomes 4. Nothing about "b". The thing is, python won't remember the previous line once executed. We can say it won't hold grudges, fresh start every time you want to assign a value to the variable, it doesn't really haunts it's past, simply new identity is given. Hope it helps, kinda childish but with good intention :)
14th Oct 2016, 7:25 PM
Adwait
Adwait - avatar
+ 1
Basically, program runs from left to right and top to bottom. So the answer will be 5 here.
18th Jan 2017, 9:38 PM
Shahriyar Shuvo
Shahriyar Shuvo - avatar
0
The output will be: 5 since, value of a(5) is assigned to b. after assigning b the value of a is changed so it will not be updated in b.
22nd Sep 2016, 3:28 AM
Gaurav Agarwal
Gaurav Agarwal - avatar
- 1
hello
26th Oct 2016, 9:32 PM
Tyler Mai
Tyler Mai - avatar
- 1
wow its good question!
20th Nov 2016, 10:28 AM
김동률
김동률 - avatar
- 1
Neat little puzzle to get someone (like me) unused to thinking this way a bit of exercise, nice :)
24th Dec 2016, 8:43 AM
Josh NoBusinezz
Josh NoBusinezz - avatar