博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

py-day3-3 python 函数的作用域

Posted on 2019-02-24 22:48  MJ-majun  阅读(192)  评论(0编辑  收藏  举报
def test1():
    print('in the test1')
def test():
    print('in the test')
    return test1

print(test)
res = test()
print(res())

in the test
in the test1
None
def foo():
    name = 'majun'
    def bar():
        name = 'mmj'
        def tt():
            print(name)
        return tt
    return bar

bar = foo()
tt = bar()
print(tt)
tt()
foo()()()

<function foo.<locals>.bar.<locals>.tt at 0x0000019B87157C80>
mmj
mmj