This article describes process control (conditional statements and circular statements) in Python
1, conditional statement
(1) only if
A=true
If a:
print ("A is established")
print ("I know A is established")
(2) If---else
A=true
If a: print ("A is established"
)
print ("I know A is established")
else:
print ("A does not set up")
(3) If---elif---else
A=false
b=true
If a:
print ("AAA")
elif B:
print ("bbbb")
else:
print ("CCC")
2. Circular statements
(1) for
Similar to the use of foreach
letter=[111, "Zhangshan", 7878,99] for Le in letter
:
print (LE)
Traversing using the subscript index
letter=[111, "Zhangshan", 7878,99,88] for
index in range (len):
print (Letter[index))
With else for, when the condition is not true, execute else
letter=[111, "Zhangshan", 7878,99] for Le in letter
:
print (le)
else:
print ("Loop over")
(2) While note: There is no do---in python while
General while
A=1 while
a<=4:
print (a)
a+=1
A while with else, executing else when the condition is not true
I=0 while
i<5:
print ("i")
i+=1
Else:
print ("Conditional not set")