python - python中使用for语句的无限循环

标签 python python-2.7

我知道

while True:
    condition to break loop

将导致无限循环。但我想对“for”语句做同样的事情。有人请帮助我

最佳答案

使用无限迭代器,如 itertools.count , itertools.cycle , itertools.repeat无限产生元素:

for i in itertools.repeat(1):
    # do something

关于python - python中使用for语句的无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36134213/

相关文章:

python - QTreeview Pyside 中的搜索过滤器

python - 函数列 Python

python-2.7 - 在函数装饰器中使用 pytest 固定装置

重定向到同一 URL 的 Python 社交身份验证

python - 根据上一列中的用户输入/内容在数据库中创建新列

python - 无法用python读取字典文件中输入的内容

python - 每隔一行遮荫

python - 确定 lambda 函数中调用的方法

python - Codewars 中止 : process was terminated. 完成时间超过 12000 毫秒

python - Matplotlib : Default Resolution of Plot Mouse-over Values