Very good basic grammar python loop

while loop
The general form in Python while statement:
while judging criteria: statement
Infinite loop
We can never achieve infinite loop to false by the conditional expression, examples are as follows:
Use CTRL + C to exit the current infinite loop.
Infinite loop in real time to client requests very useful on the server.
while recycling else statement
In while ... else statement block is executed else in the conditional statement is false:
 
for statement
Python for loop can iterate any sequence of items, such as a list or a string.

 

 

 

 

 

 
If the result of break is not performed

 

 
range () function
If you need to traverse a sequence of numbers, you can use the built-in range () function. It will generate the number of columns, for example:

 

You can also use the value range of the designated section:

 

Can also range starts with the specified number and specify a different increment (even negative, sometimes also called the 'step'):

 

Binding range () and len () function to traverse a sequence index, as follows:

 

 

 

break and continue statements and loop else clause
break statement can jump out of the loop for a while and. If you break out or for while loop, any corresponding loop else block is not executed.
continue statement is used to tell Python skip the remaining statements in the current loop block, and then proceed with the next cycle.
 
Loop else clause can have it in an exhaustive list (with a for loop) or the condition becomes false (with while loop) cause to be executed when the loop terminates, but does not perform the loop is terminated break.
The pass statement - master
Python pass is an empty statement, in order to maintain the integrity of the program structure.
pass without doing anything, generally used as a placeholder sentence, the following examples
 

Guess you like

Origin www.cnblogs.com/TomBombadil/p/10979352.html