【发布时间】:2015-07-26 11:41:29
【问题描述】:
我在网上找到了下面这段代码,实际是output
def countdown(start):
print start
if start == 0:
yield 0
else:
yield countdown(start -1)
g = countdown(3)
g.next()
g.next()
代码的输出是
3
StopIteration
谁能帮我分解这段代码,next() 是否跳过了生成器的序列?我似乎无法理解这里的流程
【问题讨论】:
-
你希望
yield countdown(start - 1)做什么?