def say_hi():
while True:
ret0 = "heihei"
print("---------before------------")
msg = yield ret0 #yield后的内容ret0,返回给外面res_out=g.send(1) print("say hi", msg)
print("---------after------------") 运行一:
g = say_hi()
next(g) 输出一:
---------before------------
运行二:
g = say_hi()
next(g)
res_out=g.send(1)
print("外面的返回值:",res_out) 输出二:
say hi 1
---------after------------
---------before------------
外面的返回值: heihei