+ 3
Why this output?
I can't understand why this result. https://code.sololearn.com/cQhUHQIMBnZb/?ref=app
2 Antworten
+ 3
"for i in list" means assigning "i" to every element in a list on each loop. Therefore "for a[-1] in a" means assigning "a[-1] = a[element]".
In your code the list changes at every loop:
1st loop: [0,1,2,3,0]
2nd [0 1 2 3 1]
3rd [0 1 2 3 2]
4th [ 0 1 2 3 3]
5th [0 1 2 3 3]
So at final loop "a[-1]" is 3
+ 1
the a[-1] in the for loop becomes your variable for holding values in a