JasonLaw:
我正在阅读functional programming – Can you explain closures (as they relate to Python)? – Stack Overflow,在这个回答中有以下代码。
def make_counter():
i = 0
def counter(): # counter() is a closure
nonlocal i
i += 1
return i
return counter
c1 = make_counter()
c2 = make_counter()
print (c1(), c1(), c2(), c2())
# -> 1 2 1 2
我的疑问:ta 说 counter() is a closure ,应该是 counter is a closure ,对吧?
from V2EX-最新主题 https://ift.tt/CUhiFnO
福利APP推荐:https://niucnet.notion.site
广告投放:https://t.me/cnxalex
牛C网:https://j1o.net
牛C网导航:https://niuc2.com
福利APP合集:https://j1o.net/share/1678.html
- 本文固定链接: https://niul.net/423922.html
- 转载请注明: 分享菌 于 牛C网(NiuL.Net) 发表