1. yield from
def gen():for c in 'AB':yield cfor i in range(1, 3):yield ilist(gen())
['A', 'B', '1', '2']
可以改写成:
def gen():yield from 'AB'yield from range(1, 3)list(gen())
['A', 'B', '1', '2']
参考:
- python协程2:yield from 从入门到精通
def gen():for c in 'AB':yield cfor i in range(1, 3):yield ilist(gen())
['A', 'B', '1', '2']
可以改写成:
def gen():yield from 'AB'yield from range(1, 3)list(gen())
['A', 'B', '1', '2']
参考: