global 全局变量
>>> def myfun():
global count
count = 10
print(10)
>>> myfun()
10
>>> count
10
>>>
内嵌函数
>>> def fun1():
print("fun1正在被调用")
def fun2():
print("fun2正在被调用")
fun2()
>>> fun1()
fun1正在被调用
fun2正在被调用
>>>
闭包closure
>>> def funx(x):
def funy(y):
return x * y
return funy
>>> i = funx(8)
>>> i
<function funx.<locals>.funy at 0x0000015C67A6BAF0>
>>> i(5)
40
>>> def fun1():
x= 5
def fun2():
nonlocal x
x *= x
return x
return fun2()
>>> fun1()
25