I am coming to ask you another basic question again. :) I want to change a list via for-loop.(sorry to bother, but i am new....)
Here is the first script:
L=[1,2,3]
i=0
for a in L:
L[i]+=1
i+=1
print(L)
print(a)
I got:
L:[2,3,4]
a: 3
This is exactly what i want. But i notice that if i change the script to this:
L=[1,2,3]
for i in L:
i+=1
print(L)
print(i)
And i got:
L:[1,2,3]
i:4
I can understand that i must be 4. But the question is why the list L doesn't change. In my opinion, the objects in the list are given to the variable i. So variable i is the one who can edit the object. So basically, the list should change. Actually, however, it stays the same.
Can someone explain this?
Thank you!