这是我写的代码:
def genFunc():
while True:
val = yield True
print(val)
myGen = genFunc()
next(myGen)
next(myGen)
myGen.send("Sending a message!")
next(myGen)
next(myGen)
在 .py 文件中运行它会返回以下内容:
None
Sending a message!
None
None
在 jupyter 单元(或 vscode python 交互式环境)中运行它会将其返回为两个单独的输出块:
None
Sending a message!
None
None
True
我没有任何合理的解释为什么会发生这种情况