How to implement infinite loop in python

爱喝马黛茶的安东尼
Release: 2019-06-20 10:47:58
Original
29774 people have browsed it

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.

How to implement infinite loop in python

The control structure diagram of Python loop statement is as follows:

How to implement infinite loop in python
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!"
Copy after login

for loop

class Infinit: def __iter__(self): return self def __next__(self): return None for i in Infinit(): print("好嗨哟,你是不是学会了Python的无限循环!") print("我是永远不会执行到的")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!