Python学习笔记------函数的作用域

 
 
def foo():
    name = 'lhf'

    def bar():
        name = 'wupeiqi'
        print(name)

        def tt():
            print(name)

        return tt

    return bar


print('返回bar的内存地址=======', foo())
print('执行bar函数=======', foo()())
print('tt函数没有返回值=======', foo()()())


# 打印结果
# 返回bar的内存地址======= <function foo.<locals>.bar at 0x1045a82f0>
# wupeiqi
# 执行bar函数======= <function foo.<locals>.bar.<locals>.tt at 0x1045a87b8>
# wupeiqi
# wupeiqi
# tt函数没有返回值======= None

猜你喜欢

转载自blog.csdn.net/weixin_39180334/article/details/81062131