Python随心记--函数作用域

案列
def test():
    print('wupangpang')
def tesst():
    return test

res = tesst()
print(res)   #会执行test()函
name = 'sss'
def foo():
    name =  'bbb'
    def bar():
        name = 'ccc'
        print(name)
    return  bar
a = foo()
print(a)
a()
def foo():
    name = 'ss'
    def bar():
        name = 'cc'
        def tt():
            print(name)
        return tt
    return bar
bar = foo()
foo()()()   #第二个括号表示运行bar() 第三个函数表示运行tt()函数

猜你喜欢

转载自www.cnblogs.com/Essaycode/p/10087254.html