0
Whatâs happening here?
a=[1,1,2,3,5,8] for a[1] in a: pass print(a) ââââââââ- Result: [1,8,2,3,5,8]
4 RĂ©ponses
+ 1
Well technically nothing is happening since syntax and capitalization is incorrect
a=[1,1,2,3,5,8]
for a[1] in a:
Pass
print(a)
And whats happening is its taking the second element of the list and replacing it with the entire list and printing that same list again but with the second element changed to one of the other elements in order from left to right.
+ 1
The 2nd element in the list which is 1 is going to become an 8 thats whats going to happen because thats how for loops work its iterating through the a list to change the second element to the last element of the list
0
only The capitalisation is incorrect as I typed it on my phone. Ive fixed it now. You changed the indentation which is not in my initial code.
Sorry I donât understand your explanation.
0
ok thanks, i think i got it