Infinite for loops possible in Python?
问题 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 references. 回答1: The quintessential example of an infinite loop in Python is: while True: pass To apply this to a for loop, use a generator (simplest form): def infinity(): while True: yield This can be used as follows: for _ in infinity(): pass 回答2: To answer your question using a for loop as requested, this would loop forever as 1 will never be