[Tutor] scope/namespaces

Rikard Bosnjakovic rikard.bosnjakovic at gmail.com
Tue Apr 24 11:21:01 CEST 2007


On 4/24/07, ammar azif <ceasar102 at yahoo.com> wrote:

> i am able to access the variable declared in that loop after the loop
> finishes which i am not able to do in languages like c/c++ or java. Is it
> different in python?

I'm not sure what you mean with "different", but the loop-variable is
not destroyed upon the exit of the for-loop:

>>> z
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'z' is not defined
>>> for z in (1,2,3): pass
...
>>> print z
3


-- 
- Rikard - http://bos.hack.org/cv/


More information about the Tutor mailing list