๐น Step 1: range(3)
range(3) creates a sequence of numbers:
➡️ 0, 1, 2
๐น Step 2: for i in range(3):
The loop runs three times, and i takes these values one by one:
-
1st iteration → i = 0
-
2nd iteration → i = 1
-
3rd iteration → i = 2
The pass statement means “do nothing”, so the loop body is empty.
๐น Step 3: After the loop ends
Once the loop finishes, the variable i still holds its last value — which is 2.
๐น Step 4: print(i)
This prints the final value of i, i.e.:
✅ Output:
2Key takeaway:
Even after a for loop ends, the loop variable keeps its last assigned value in Python.


0 Comments:
Post a Comment