Why does "3" get printed out in this code block's output:
Input:
n = range(4)
for num in n:
print(num - 1)
else:
print(num)
Output:
-1
0
1
2
3
From my understanding, "3" should not be printed since:
- num will never equal "4" since n are the literals 0 through 3 (not inclusive of 4),
- when num equals its highest literal, which is "3", it will print "2".
I've read the question about the else statement in for and while loops in Python, but I do not see an iteration where "4" is called in the for loop hence triggering the any usage of the else statement since num stops at 3.
Thank you.