作业
Topic source1、闭包就是能够在外层函数的外部读取(要赋值的话需先在内层函数也就是闭包中用nonlocal声明)其局部变量的内层函数
2、闭包能够将外层函数局部变量与外层函数的外部联系起来
3、闭包能够使外层函数的局部变量能够持久地保存在内存中(因为调用外层函数之后,返回的函数还没被调用)
- 1
1、闭包就是能够在外层函数的外部读取(要赋值的话需先在内层函数也就是闭包中用nonlocal声明)其局部变量的内层函数
2、闭包能够将外层函数局部变量与外层函数的外部联系起来
3、闭包能够使外层函数的局部变量能够持久地保存在内存中(因为调用外层函数之后,返回的函数还没被调用)
极大似然
def createCounter():
t = 0
def counter():
nonlocal t
t = t + 1
return t
return counter