16 lines
286 B
Python
16 lines
286 B
Python
|
|
""""
|
|
nonlocal 是一个关键字
|
|
用于在嵌套函数(即内部函数)中修改外层函数(非全局作用域)中的变量。
|
|
"""
|
|
def fun1():
|
|
b = 100
|
|
def fun2():
|
|
nonlocal b
|
|
b = 300
|
|
print(b)
|
|
fun2()
|
|
print(b)
|
|
fun1()
|
|
print('----')
|
|
print(b) |