I'm trying to modify item in a list using IN and Indexing. While modifying via indexing, the item was actually changed. However, when I try to change via IN keyword, it seems that the item in the list does not change.
- What's the difference between both method internally?
- When using IN, does it mean that you iterate through the list and assign the value of each item in the variable in for statement?
lines = ['hi', 'hello']
for line in lines:
line += '*'
for i in range(len(lines)):
lines[i] += '#'
print(lines)
Output:
['hi#', 'hello#']