使用生成器
def counts():
def f(): # 尽量使用这种生成器
x = 0
while True:
x = x + 1
yield x
it = f()
def number():
num = next(it)
return num
return number
counts_demo = counts()
while True:
num = counts_demo()
print(num)
if num > 10:
break