1、可以简单理解为return
2、函数中有yield关键字,函数并不会真的执行,而是先得到一个生成器g(相当于一个对象)
3、直到调用next方法,函数正式开始执行
import time
def foo():
time.sleep(3)
yield 2000
def co():
res = None
f = foo()
try:
while True:
res = next(f)
except StopIteration:
return res
if __name__ == '__main__':
print(co())