学到了林海峰,武沛齐讲的Day19 迭代细讲

在家加1个月学了8day的课  出差6天看了8day的课..说明再忙也是可以挤挤多学习的.

广州出差最后两天没学习.一天做车,一天做公司的事...4天就过去了.

老师讲的包子和鸡蛋需求不好...讲的有点绕.

def test():
    yield '早上吃早饭'
    yield '中午干农活'
    yield '晚上打麻将'
g=test()
print(g.__next__())
print('做些其他事1')
print(g.__next__())
print('做些其他事2')
print(g.__next__())
print('做些其他事3')

上面这个例子好理解

import time
def consumer(name):
    print('我是[%s],我准备开始吃包子了' %name)
    while True:
        baozi=yield
        time.sleep(1)
        print('%s 很开心的把【%s】吃掉了' %(name,baozi))
def producer():
    c1=consumer('wupeiqi')
    c2=consumer('yuanhao_SB')
    c1.__next__()
    c2.__next__()
    for i in range(10):
        time.sleep(1)
        c1.send('包子 %s' %i)
        c2.send('包子 %s' %i)
producer()

send()用法.做记录了,不然想到办法不知道函数.

猜你喜欢

转载自www.cnblogs.com/gxrwsb/p/11602862.html