在Python 2中,当函数定义中的return与yield一起时,出现了错误.但对于Python 3.3中的这段代码
def f(): return 3 yield 2 x = f() print(x.__next__())
没有错误,返回用于带有yield的函数.但是,当__next__调用该函数时,会抛出异常StopIteration.为什么不只是返回价值3?这种回报是否被忽略了?
__next__
3
python generator python-3.x
generator ×1
python ×1
python-3.x ×1