Python Control Flow
In this post
if, for and while — how Python chooses what to do next.
if, for and while — how Python chooses what to do next.
Choosing
Indentation marks the block, so how the code looks and what it means cannot disagree.
score = 72
if score >= 80:
print("distinction")
elif score >= 50:
print("pass")
else:
print("retake")
Output:
pass
Repeating
A for loop walks a sequence directly rather than counting an index towards its length.
for word in ["read", "run", "repeat"]:
print(word.upper())
Output:
READ
RUN
REPEAT
Next
Carry on to the next tutorial in the rail — it picks up where this one leaves off.
PythonControl Flow