I have a weird Python beginner's question,.. playing around in my virtual env in the interpreter (python 3.5):
I have a list with mixed types:
lissi = ["foo", "bar". "boo", "baz", 4, 7]
for x in lissi:
print("Hallo " + x)
"x" and enter
It's not a backlog and nothing like "every successfully processed element is removed".
Basically on every iteration
for loop assigns to variable
x the value of next element of list
lissi (doesn't have to be a list, can be any iterable).
Whenever the loop breaks, due to exception or
break statement, variable
x is left intact, so it contains the last value assigned by the
This is ok, since loops don't have any isolated scope in Python and actually makes it convenient to search iterable for interesting element, breaking the loop when it's found and not being forced to store it in another variable before leaving the loop.