def create_counter():
i = 0
def counter():
nonlocal i
while True:
i += 1
yield i
return counter
gc = create_counter()()
print([next(gc) for i in range(10)])
Sign in to make a reply
郁闷~喝可乐
def create_counter():
i = 0
def counter():
nonlocal i
while True:
i += 1
yield i
return counter
gc = create_counter()()
print([next(gc) for i in range(10)])