(no title)
carbonica | 14 years ago
>>> i = 10
>>> def x():
... print i
...
>>> x()
10
>>> i = 11
>>> x()
11
The value is not closed over in any language I can think of off the top of my head. It's a reference to a variable in lexical scope.What python does slightly differently is writing to variables in outer scopes. But it still closes over references.
Jach|14 years ago
Edit: I guess it should be said that Python 3 has the 'nonlocal' keyword, and Python 2 has the 'global' keyword for global cases, which allows for expected behavior. So the functionality is still there, but still needs an extra statement.
enneff|14 years ago