I am new to Python language and used C++ for the previous 2 years. I am trying to understand why these two codes produce different results:
The first for loop:
l1=[1,2,3,4,5]
for i in l1:
i+=10
print l1
# [1,2,3,4,5]
The second for loop:
l1=[1,2,3,4,5]
for i in range(len(l1)):
l1[i]+=10
print l1
# [11,12,13,14,15]
Why doesn't the first loop produce the same result? I thought that the "for i in object" does the dereferencing for you and gives you access to the object's value?