目录
#例5 利用yield from语句向生成器(协程)传送数据
简单入门用法:
def g(x):
# yield from range(x, 0, -1)
yield from range(x)
print(list(g(5)))
def my_generator():
for item in [1,2,3]:
yield item
print(list(my_generator()))
二级函数用法
def sub_generator():
for i in range(5):
yield i
def main_generator():
yield from sub_generator()
# 使用生成器
for value in main_generator():
print(value)