I'm quite new to Python and I learned something interesting.
item = 5
for item in [1, 2, 3]:
pass
print(item)
Result:
3
I expected 5 because I thought the variable inside the a for loop would be local to its scope but it wasn't.
I think it is not good since I might accidentally write global variable name in a for loop.
How do people usually deal with the potential problem? Is there a way to make the variable local to the scope?