Home>Article>Backend Development> How to implement infinite loop in python
How to implement infinite loop in Python? Loop statements in Python include for and while. Infinite loop statements can be constructed in two ways: for and while.
The control structure diagram of Python loop statement is as follows:
Related recommendations: "python video tutorial》
while loop
var = 1 while var == 1 : # 该条件永远为true,循环将无限执行下去 num = raw_input("Enter a number :") print "You entered: ", num print "Good bye!"
for loop
class Infinit: def __iter__(self): return self def __next__(self): return None for i in Infinit(): print("好嗨哟,你是不是学会了Python的无限循环!") print("我是永远不会执行到的")
The above is the detailed content of How to implement infinite loop in python. For more information, please follow other related articles on the PHP Chinese website!