+ 1

Can anyone explain how works this python code?

a = [1, 1, 2, 3, 5, 8] for a[1] in a: pass print(a) #output: [1, 8, 2, 3, 5, 8]

11th Aug 2019, 7:47 PM
<<Meowg!i>>
<<Meowg!i>> - avatar
1 Answer
+ 2
a iterates over a[1], so a is 1, then 1, then 2, then 3, then 5, then 8; and it stays 8 after the loop has ended
11th Aug 2019, 7:51 PM
Airree
Airree - avatar