作用域
- L local
局部作用域 - E enclosing
嵌套的父级函数的局部作用域,即包含此函数的上级函数的局部作用域 - G globa
全局变量,就是模块级别定义的变量 - B built-in
系统固定模块里面的变量,比如int, bytearray等 - 搜索变量的优先级顺序依次
作用域局部>外层作用域>当前模块中的全局>python内置作用域
L--E--G--B
x=int(2.9)
g_count=0 #G
def outer():
e_count=1 #E
def inner():
l_count=2 #L
print(e_count)
pass
inner()
outer()
# local和enclosing是相对的,enclosing变量相对上层来说也是local
# def、class、lambda是可以引入新作用域的
关键字
- global
- nonlocal
网友评论