- 1
a = [1,2,3] for a[-1] in a: print(a[-1])
Try to solve this simple question why is the output 1,2,2 why 1,2,3
1 Resposta
+ 3
a[-1] assigned 1 on first iteration,list a is now [1,2,1]
a[-1] assigned 2 on second iteration ,list a is now [1,2,2]
a[-1] is assigned 2 again during third iteration ,
And so you can see why it prints 1,2,2