Modify list items


Hi, just wondering why the values in the list could not be doubled in this way, although I know another way of calling index could work.

for item in a:
print a


item is a local variable only existing inside the for loop, it gets re-assigned for the next run of the loop, and it cease to exist after the loop is finished. So your updates aren't stored anywhere, which is why it isn't working


So can I understand it like this. "for x in lists", the system created a local variable name "x",each time "x" is assigned to different value in lists. "x" is a copy of the value in lists, not a part of lists itself.


I would put it the other way around: x gets assigned a (copy of) value of the list.

Yep, this is absolutely right. Where as x would be a index, you use it to access the list, and then update a value in the list. You seem to have understand in perfectly


thanks stetim, absolutely helpful!