举例说明:
1.
name = 'john' def foo(): name = 'xiaomming' def bar(): print(name) return bar a=foo() print(a) a()
运行结果:
<function foo.<locals>.bar at 0x0382A6A8> # 内存地址
xiaomming
Process finished with exit code 0
2.
def foo(): name = 'xm' def bar(): ‘’‘ name = 'xh' def abc(): print(name) 作用域 return abc return bar ’‘’ foo()()()
运行结果:
xh
Process finished with exit code 0