#LEGB法则--变量的查找顺序
a = 1
def outer():
b = 2
def inner():
c = 3
print(c) # local局部作用域
print(b) # enclosing嵌套函数的外部函数作用域
print(a) # global全部作用域
print(max) # 内置作用域
inner()
outer()
运行结果
3
2
1
python 的LEGB法则--变量的查找顺序
最新推荐文章于 2024-04-16 15:07:56 发布