主页
Python
Python 生成器
demo_generator_yield
运行 ❯
×
更改方向
保存代码
更改主题
def count_up_to(n): count = 1 while count <= n: yield count count += 1 for num in count_up_to(5): print(num)
1
2
3
4
5