Unexpected result.

Grzegorz Dostatni grzegorz at ee.ualberta.ca
Thu Sep 23 13:18:08 EDT 2004


Consider the following fragment:

>>> for i in ('a','b','c'):
...     for i in (1,2,3):
...             print i,
...     print i,
...
1 2 3 3 1 2 3 3 1 2 3 3

Now. I believe I know what is happening. The i in both loops refers to the
same variable. My question is whether it would make more sense (be more
intuitive) to have a for loop create its own local scope. (ie. an output
string of
1 2 3 a 1 2 3 b 1 2 3 c

)

Grzegorz


"Some cause happiness wherever they go; others, whenever they go."
	- Oscar Wilde (1854-1900)





More information about the Python-list mailing list