一.简单示例
def yield_func():
for _ in range(2):
yield "12"
def yield_from_func():
for _ in range(2):
yield from '12'
for a in yield_func():
print(a)
for a in yield_from_func():
print(a)
'''
12
12
1
2
1
2
'''
很明显就能看出来yield from就是把迭代器再进行一次迭代器生成可以想象成[12,12]变成[1,2,1,2]把里面第一次迭代后的每个值再进行一次迭代