生成器的应用-协程

def test1():
    while True:
        print('---1---')
        yield None

def test2():
    while True:
        print('---2---')
        yield None

t1 = test1()
t2 = test2()
while True:
    t1.__next__()
    t2.__next__()

控制台打印:交替不停打印

 

posted @ 2018-04-27 15:38  liuw_flexi  阅读(109)  评论(0编辑  收藏  举报