Python scoping

gervaz gervaz at gmail.com
Mon Jun 20 18:35:35 EDT 2011


Hi all, can you explain me why this simple function works well (i.e. I
can call the print function using txt) in py

>>> def test(value):
...     if value%5: txt = "hello"
...     else: txt = "test"
...     print(txt)

while in other languages like C the txt identifier would be undefined?
Is there a way to force the scoping?


Thanks,

Mattia



More information about the Python-list mailing list