封闭封闭
def make_counter(): i = 0 def counter(): # counter() is a closure nonlocal i i += 1 return i return counterc1 = make_counter()c2 = make_counter()print (c1(), c1(), c2(), c2())# -> 1 2 1 2
欢迎分享,转载请注明来源:内存溢出
封闭封闭
def make_counter(): i = 0 def counter(): # counter() is a closure nonlocal i i += 1 return i return counterc1 = make_counter()c2 = make_counter()print (c1(), c1(), c2(), c2())# -> 1 2 1 2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)