python 装饰器 闭包函数的具体细节

‘’‘闭包函数的具体细节’’’
def counter(start=0):
def infuc():
nonlocal start
start += 1
print(‘此时内部函数调用的结果是:’,start)
return infuc#返回内部函数
if name == ‘main’:
mycount = counter(4)
mycount()
‘’‘在python3中,用nonlocal进行环境变量的声明,再修改环境变量’’’
在这里插入图片描述
运行结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44737399/article/details/89161798