python学习-26 函数作用域
程序员文章站
2022-07-09 21:03:03
举例说明: 1. 运行结果: 2. 运行结果: ......
举例说明:
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
上一篇: 如何利用swoole搭建一個簡易聊天室
下一篇: Shell学习心得(四):流程控制