【发布时间】:2019-05-08 01:14:21
【问题描述】:
你能解释一下为什么在示例中从未执行过 except 子句并且从未调用过 print 吗?
def h(lst):
try:
yield from lst
except StopIteration:
print('ST')
t = h([1,2])
next(t)
>>> 1
next(t)
>>> 2
next(t)
>>> Traceback (most recent call last):
File "<ipython-input-77-f843efe259be>", line 1, in <module>
next(t)
StopIteration
【问题讨论】: