Demo1:
def cs(p):
a=1
print('cs:',p)
while True:
a = yield a+100
print(p,a)
#
g=cs('htzd')
res=g.send(None) # next(g)
print(res)
#
res=g.send(1000)
print(res)
#
res=g.send(2000)
print(res)
Demo2:
def dog(name):
food_list=[]
print('道哥%s准备吃东西啦...' %name)
while True:
# x拿到的是yield接收到的值
x = yield food_list # x = '肉包子'
print('道哥%s吃了 %s' %(name,x))
food_list.append(x) # ['一根骨头','肉包子']
#
g=dog('alex')
res=g.send(None) # next(g)
print(res)
#
res=g.send('一根骨头')
print(res)
#
res=g.send('肉包子')
print(res)