I am trying to understand, how exactly variable binding in python works. Let\'s look at this:
def foo(x): def bar(): print y return bar y =
Nothing strange, it is because "x" from function argument has higher priority than global variable "x".
At first, global variables is a great evil.
Python has operator "global":
>>> def foo(x): ... def bar(): ... global x ... print x ... return bar ... >>> x = 5 >>> bar = foo(2) >>> bar() 5