But if a return is encountered, it causes the produced generator to raise a StopIteration exception rather than yield further values.
但如果遇到return,它导致产生的生成器抛出StopIteration异常,而不是进一步生成值。
A generator "returns" with the new keyword yield, but "remembers" the exact point of execution where it returned.
生成器“返回”时带关键字yield,但“记住”了它“返回”的所有确切执行位置。
Every yield encountered becomes a return value for generator's.next method. Let's look at the simplest generator to make things clear.
遇到的每个yield都成为生成器的. next方法的返回值。
应用推荐