Python program control process-three major processes

Program control process (three major processes):

1. Sequence: The code runs from top to bottom and from left to right.
2. Choice:
(1) Single branch: if condition: #The code is executed when the condition is established 
(2) Double branch: if condition: #When the condition is established To execute the code
                      else: If the condition is not established, execute the code
        multiple branches: if condition 1:
                      #Execute the code when the condition 1 is established elif condition 2: #Execute the code when the condition 2 is established
                      ...
                      else: #Execute the code when the previous condition is not established
Loop (while, for)

Note: (All indentation in python is either with spaces or tabs, not mixed)
(strings in Java cannot be ==, but python can)

What is a loop:
   a statement structure in which the code repeats loop

while loop
for loop

while loop:
   while condition:
         #loop body (loop until exit)  
           loop body is a subset of while 
    print ("loop ends...") where print is parallel to while
inport sys
sys.exit() //Exit the system

 

index,odd,even=0,0,0 (the definition is unique)

ctri+s interrupt cycle

Use of break and continue keywords
      break: directly terminate the loop
      continue: skip this loop and execute the next loop
. Else in the loop will only be executed after the normal execution ends, and will not be executed if it ends abnormally (forced termination)

for loop
    for variable in iterable object (container)
    for looks like
    for i in python uses to iterate iterable objects

Guess you like

Origin blog.csdn.net/weixin_45802686/article/details/108815323