'''
使用yield完成多任务
'''
# import time
# def task1():
# while True:
# print('--1--')
# time.sleep(0.1)
# yield
# def task2():
# while True:
# print('--2--')
# time.sleep(0.1)
# yield
# def main():
# t1 = task1()
# t2 = task2()
# while True:
# next(t1)
# next(t2)
#
#
# if __name__ == '__main__':
# main()
'''yield from介绍
python3 新加了yield from语法
'''
from itertools import chain
# lis = [1,2,3]
# dic = {
# 'name':'ellen',
# 'age':18
# }
# chain 相当于实现了3个for循环
# 返回一个对象<itertools.chain object at 0x00000000026A8748>
# 加list 强制转换后结果:[1, 2, 3, 'name', 'age', 5, 6, 7, 8, 9]
# print(list(chain(lis,dic,range(5,10))))
# *args,**kwargs 不定长参数
# def my_chain(*args,**kwargs):
# for my_iterable in args:
# # for value in my_iterable:
#
yield完成多任务
最新推荐文章于 2020-09-12 09:52:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)