How to write python loop statement
Jul 20, 2019 am 10:30 AMThe while statement in Python programming is used to execute programs in a loop, that is, under certain conditions, execute a certain program in a loop to handle the same tasks that need to be processed repeatedly.
The basic form is: (Recommended learning: Python video tutorial)
while 判断条件: 执行语句……
The execution statement can Is a single statement or block of statements. The judgment condition can be any expression, and any non-zero or non-null value is true.
When the judgment condition is false, the loop ends.
There are two other important commands in the while statement: continue, break is used to skip the loop, continue is used to skip the loop, and break is used to exit the loop.
In addition, the "judgment condition" can also be a constant value, indicating that the loop must be established. The specific usage is as follows:
# continue 和 break 用法 i = 1 while i < 10: i += 1 if i%2 > 0: # 非双数时跳过输出 continue print i # 输出双数2、4、6、8、10 i = 1 while 1: # 循环条件为1必定成立 print i # 输出1~10 i += 1 if i > 10: # 当i大于10时跳出循环 break
For more Python related technical articles, please visit Python Tutorial Column for learning!
The above is the detailed content of How to write python loop statement. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
