0

COULD SOMEONE EXPLAIN WHY THE OUTPUT IS 10?

for a in [1,2,3,4,5]: a+=a print(a)

25th Nov 2018, 2:47 AM
Faye Andrea Tan
Faye Andrea Tan - avatar
2 Answers
+ 5
a = 1+1 a = 2+2 a = 3+3 a = 4+4 a = 5+5 <<<10
25th Nov 2018, 3:00 AM
James
James - avatar
0
a+=a means "a=a+a" But you have not take any temp variable to store the previous result. So it just giving you the last result Here 5+5 =10
25th Nov 2018, 5:09 AM
Mahfuza Mousumi