python: how binding works

前端 未结 5 1631
难免孤独
难免孤独 2021-01-04 13:26

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 =          


        
5条回答
  •  滥情空心
    2021-01-04 14:23

    It is mater of scope, second example uses local scope variable x, that is preceded above globally declared

提交回复
热议问题