Chapter IV branching and looping
Ternary operator
a = x if条件 else y
Affirmation
assert (), when the keyword behind the condition is false, the program throws an exception.
for loop
for expression in the target \ list
loop
>>> fa = "fishc"
>>> for each in fa:
print(each,end = " ")
f i s h c
range()
range ([start,] stop [ , step = 1])
generates a start parameter value starting from the digital value to the end stop parameter.
If the range () passing only a number, such as 5, the production of all numbers from 0 to 5 (but not including 0 5)
>>> for i in range(5):
print(i)
0
1
2
3
4
Pass two parameters
>>> for i in range(2,9):
print(i)
2
3
4
5
6
7
8
Passes three parameters
>>> for i in range(1,10,2):
print(i)
1
3
5
7
9
break statement
Terminate the current cycle, out of the loop body.
continue Statement
Terminate the current round of the cycle and the beginning of the next cycle