0

could someone please explain the answer briefly

a=[0,1,2,3] for a[-1] in a: print(a[-1])

11th Feb 2020, 2:49 PM
Radhey
Radhey - avatar
2 Answers
+ 3
for x in y means: 'Please let x be each element of y consecutively.' This is comparable to you just writing: x = y[0] x = y[1] and so forth. Now for a[-1] means that instead of a variable x, the last slot of a is taken as the 'vessel' where each element will be stored.
11th Feb 2020, 3:14 PM
HonFu
HonFu - avatar
+ 1
Thank you HonFu
11th Feb 2020, 5:53 PM
Radhey
Radhey - avatar