产生序列0,1,2,3的发电机
Python是否提供了生成无尽序列0,1,2,3的函数?
实施它很容易:
def gen_range():
count = 0
while True:
yield count
count = count + 1
但是我想,这已经存在于Python中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。查看
itertools.counts.counts.counts.counts.counts.counts
内置功能。正如您可以在链接的文档中阅读的那样,您可以设置起始号码以及步骤。还允许浮子数字。您可以使用它:
这将打印0、1、2、3,...(要小心!此示例直到您强迫以某种方式停止它才会停止)。
Yes it does. Check out the
itertools.count
built-in function. As you can read in the linked docs, you can set the starting number and also the step. Float numbers are also allowed.Here's how you can use it:
This is going to print 0, 1, 2, 3, ... (Be careful! This example won't stop until you force it to stop somehow).