For loop

We know that the value of the variable is updated by the for loop itself right.
But on executing the following two pieces of codes :
1.for i in range(len(string)):
print(i)
i=i+1
2.for i in range(len(string)):
print(i)

I got the same output. How is this possible?
Shouldn’t the first output be : 0 2 4… and second output be 0 1 2 …

In example 1, every time you return to the ‘for’ statement, the value of the iteration variable is over-written by the next value in line.

From the docs:

The for-loop makes assignments to the variables(s) in the target list. This overwrites all previous assignments to those variables including those made in the suite of the for-loop:

Add a second print() expression:

string = 'abc'
for i in range(len(string)):
    print("loop i ", i)
    i=i+1
    print("updated i ", i)

# Output:
loop i  0
updated i  1
loop i  1
updated i  2
loop i  2
updated i  3