def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield
print("货物[%s]已经被%s搬进仓库了。"%(goods,name))
p = put_on("bigberg")
#输出
G:pythoninstallpython.exe G:/python/untitled/study4/test/double.py
Process finished with exit code 0
print(type(p)) #输出 <class 'generator'>
def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield #遇到yield中断
print("货物[%s]已经被%s搬进仓库了。"%(goods,name)) #中断后运行部分
p = put_on("bigberg")
p.__next__()
#输出
Hi bigberg, 货物来了,准备搬到仓库!
def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield
print("货物[%s]已经被%s搬进仓库了。"%(goods,name))
p = put_on("bigberg")
p.__next__()
p.__next__()
#输出
Hi bigberg, 货物来了,准备搬到仓库!
货物[None]已经被bigberg搬进仓库了。
def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield
print("货物[%s]已经被%s搬进仓库了。"%(goods,name))
p = put_on("bigberg")
p.__next__()
p.send("瓜子")
#输出
Hi bigberg, 货物来了,准备搬到仓库!
货物[瓜子]已经被bigberg搬进仓库了。
def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield
print("货物[%s]已经被%s搬进仓库了。"%(goods,name))
p = put_on("bigberg")
p.__next__()
p.send("瓜子")
p.send("花生")
p.send("饼干")
p.send("牛奶")
#多次调用send()
Hi bigberg, 货物来了,准备搬到仓库!
货物[瓜子]已经被bigberg搬进仓库了。
货物[花生]已经被bigberg搬进仓库了。
货物[饼干]已经被bigberg搬进仓库了。
货物[牛奶]已经被bigberg搬进仓库了。
import time
def put_on(name):
print("Hi {}, 货物来了,准备搬到仓库!".format(name))
while True:
goods = yield
print("货物[%s]已经被%s搬进仓库了。"%(goods,name))
def transfer(name):
p = put_on('A')
p2 = put_on('B')
p.__next__()
p2.__next__()
print("%s将货物送来了!"%name)
for i in range(5):
time.sleep(1)
print("%s递过来两件货物"%name)
p.send("瓜子")
p2.send("花生")
transfer("bigberg")
#输出
Hi A, 货物来了,准备搬到仓库!
Hi B, 货物来了,准备搬到仓库!
bigberg将货物送来了!
bigberg递过来两件货物
货物[瓜子]已经被A搬进仓库了。
货物[花生]已经被B搬进仓库了。
bigberg递过来两件货物
货物[瓜子]已经被A搬进仓库了。
货物[花生]已经被B搬进仓库了。
bigberg递过来两件货物
货物[瓜子]已经被A搬进仓库了。
货物[花生]已经被B搬进仓库了。
bigberg递过来两件货物
货物[瓜子]已经被A搬进仓库了。
货物[花生]已经被B搬进仓库了。
bigberg递过来两件货物
货物[瓜子]已经被A搬进仓库了。
货物[花生]已经被B搬进仓库了。
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有