Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python Loop statement

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use the Python loop sentence, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

What is a cycle?

To understand simply, a cycle is to do something over and over again. Examples in life: for example, when we listen to music, there will be single loop, list loop, random playback and sequential playback on the song page.

The logic of looping statements in Python: execute a statement / block of code multiple times.

In programming languages, the general form of circular statements is as follows:

While cycle of Python

The while statement is used to loop through a program, that is, under certain conditions, to loop through a section of the program to handle the same task that needs to be repeated. The usage is as follows:

While judgment condition:

Execute a statement (can be a single statement or a block of statements)

Note:

1. The judgment condition can be an expression or a character.

2, it should be noted that if the value of the judgment condition is True, then there must be statements in the execution statement that change the value of the judgment condition, or there must be an operation that triggers exit, otherwise, it will enter an endless loop.

3. You can use the break or continue keywords in a loop.

Break: used to exit the loop

Continue: used to skip this loop and continue to the next loop

Run the case column:

While None: # does not meet the condition, does not enter the loop print (123) while 0: # does not meet the condition, does not enter the loop print (123) I = 0while True: # satisfies the condition, and will enter the loop if I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report