How does this code works:

Rocco Moretti roccomoretti at
Tue Jul 12 01:04:10 CEST 2005

vch wrote:
> Here's an example from some book:
> def foo(n):
>     s = [n]
>     def bar(i):
>          s[0] += i
>          return s[0]
>      return bar
> what I don't understand is how this example works, taking into account 
> the LGB rule. I thought that s is not accessible from bar, but it is, 
> apparently. Why?

Nested Scopes (Since Python 2.1):

More information about the Python-list mailing list