打印数字从1到x,其中x在python中是无穷大

Max*_*yne 2 python infinity

可能重复:
Python无限 - 任何警告?
python unbounded xrange()

我有一个关于Python的问题,你编写一个简单的脚本,打印从1到x的数字序列,其中x是无穷大.这意味着," x "可以是任何值.

例如,如果我们要打印一系列数字,它会将数字从1打印到"if"语句,表示停在数字"10"并且打印过程将停止.

在我当前的代码中,我正在使用这样的"for"循环:

for x in range(0,100):
    print x
Run Code Online (Sandbox Code Playgroud)

我试图想象如何将"范围"中的"100"替换为其他可以让循环在不指定值的情况下连续打印序列的东西.任何帮助,将不胜感激.谢谢

Lev*_*sky 14

itertools.count:

import itertools
for x in itertools.count():
    print x
Run Code Online (Sandbox Code Playgroud)

通过简单的while循环:

x = 0
while True:
    print x
    x += 1
Run Code Online (Sandbox Code Playgroud)