-2

再会!在过去的几天里,我一直在诚实地尝试消化 python“Yield from”语句的真相和工作原理……我对 Interables、Iterators、Generators 和 Yield 语句以及 Yield 语句的基本协程有了具体的理解一个表情……

但我似乎无法从...开始围绕 Yield ...

例子

def gen():
    ...
    yield from gen1 #where gen1 is another generator

大多数在线材料要么过于技术性,要么是 PEP 380 的直接引用。任何和所有帮助都将受到赞赏。提前致谢。

4

1 回答 1

0

它们是两种代码:

def gen(iter_):
    for item in iter_:
        yield item
def gen(iter_):
    yield from iter_

换句话说,yield from <item>, 产生可迭代的“item”项。

于 2021-10-11T12:50:56.990 回答