def out_eat(name):
print('%s ready to eat' %name)
food_list=['茶水']
while True:
food=yield food_list
food_list.append(food)
print('%s start to eat %s' %(name,food))
person_one=out_eat('Trump')
#1、必须初始化一次,让函数停在yield的位置
res0=person_one.__next__()
print(res0)
#2、接下来的事,就是喂狗
#send有两方面的功能
#1、给yield传值
#2、同__next__的功能
res1=person_one.send('罗宋汤')
print(res1)
res2=person_one.send('炒牛柳')
print(res2)
res3=person_one.send('鱼香肉丝')
print(res3)
D:\Python\Python36\python.exe D:/Python_test/day_lesson/test.py
Trump ready to eat
[‘茶水’]
Trump start to eat 罗宋汤
[‘茶水’, ‘罗宋汤’]
Trump start to eat 炒牛柳
[‘茶水’, ‘罗宋汤’, ‘炒牛柳’]
Trump start to eat 鱼香肉丝
[‘茶水’, ‘罗宋汤’, ‘炒牛柳’, ‘鱼香肉丝’]
Process finished with exit code 0