import time
def consume(name):
print("%s 吃包子" %name)
while True:
baozi = yield #返回存入的值
print("包子[%s]来了,被[%s]吃了!" %(baozi,name))
def produce():
c = consume('A')
c2 = consume('B')
c.__next__()
c2.__next__()
print('老子要开始吃包子了')
for i in range(10):
time.sleep(1)
print('做了两个包子')
c.send(i)
c2.send(i)
produce()
python 迭代器相关示例代码
最新推荐文章于 2023-03-25 23:53:35 发布