Why this code is working?

Peter Otten __peter__ at web.de
Wed Jan 14 04:59:31 EST 2009


Hussein B wrote:

> Why this code is working?
> 
>>>> def f1( ):
> ...      x = 88
> ...      f2(x)
> ...
>>>> def f2(x):
> ...      print x
> ...
>>>> f1( )
> 88

The name 'f2' is not resolved once when the f1 function is created. Instead
Python looks for a global name 'f2' each time f1 is executed.

Peter



More information about the Python-list mailing list