for x in... x remains global

Antoine De Groote antoine at
Wed Nov 8 12:49:23 CET 2006

for x in range(3): pass

After this statement is executed x is global variable. This seems very 
unnatural to me and caused me 3 three days of debugging because I was 
unintentionally using x further down in my program (typo). I would have 
thought that variables like this are local to the for block.

Is there a reason this is not the case? Maybe there are PEPs or 
something else about the matter that you can point me to?


More information about the Python-list mailing list