Iterating over a list in a function - Method 1 - Incorrect?


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/4?curriculum_id=4f89dab3d788890003000096


According to the lesson, "Method 1 is useful to loop through the list, but it's not possible to modify the list this way. "

However, this code works fine. [1,2,3,4] becomes [11,12,13,14] without error.

Is the lesson in error or am I misunderstanding the meaning of the above statement?


list = [1,2,3,4]

for item in list:
    item += 10
    print (item)


#2

no, inside the item is temporary increased by 10, but it doesn't modify the list, prove:

list = [1,2,3,4]

for item in list:
    item += 10
    print (item)
print list

item gets assigned a value (possible copy) from the list, which is then increased by 10, but the list itself is not modified


#3

You're spot on right. As I suspected I wasn't reading the meaning correctly.

Thank you