python中LEGB原则
1、
>>> def a():
x = 200
def b():
print("inner:",x)
return b()
>>> a()
inner: 200
2、
>>> def a():
x = 100
def b():
x = 300
print("inner:",x)
return b()
>>> a()
inner: 300
3、
>>> x = 300
>>> def a():
def b():
print("inner:",x)
return b()
>>> a()
inner: 300
4、
>>> x = 300
>>> def a():
x = 500
def b():
print("inner:",x)
return b()
>>> a()
inner: 500
5、
>>> x = 300
>>> def a():
x = 500
def b():
x = 700
print("inner:",x)
return b()
>>> a()
inner: 700