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

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
原文地址:https://www.cnblogs.com/majunBK/p/10428530.html