Infinite for loops possible in Python?

后端 未结 10 2200
误落风尘
误落风尘 2020-12-06 10:39

Is it possible to get an infinite loop in for loop?

My guess is that there can be an infinite for loop in Python. I\'d like to know this for future refe

10条回答
  •  误落风尘
    2020-12-06 11:21

    Why not try itertools.count?

    import itertools
    for i in itertools.count():
        print i
    

    which would just start printing numbers from 0 to ...

    Try it out.

    **I realize I'm a couple of years late but it might help someone else :)

提交回复
热议问题