Chapter 3: Control Flow
1. Conditional Statements
1.1 if Statement
if Statementif condition:
# Code to execute if the condition is Trueage = 18
if age >= 18:
print("You are an adult.")1.2 if-else Statement
if-else Statementif condition:
# Code to execute if the condition is True
else:
# Code to execute if the condition is False1.3 if-elif-else Statement
if-elif-else Statement1.4 Nested if Statements
if Statements1.5 Ternary Conditional Expression
1.6 Precautions with Conditionals
2. Loops
2.1 while Loop
while Loop2.2 for Loop
for Loop2.3 range() in for Loops
range() in for Loops2.4 break and continue
break and continue2.5 Nested Loops
3. Control Flow Tools
3.1 The pass Statement
pass Statement3.2 The else Clause in Loops
else Clause in Loops4. Comprehensions
4.1 List Comprehensions
4.2 Dictionary Comprehensions
5. Precautions and Tricks
Summary Table: Control Flow Tools
Control Flow Tool
Description
Example
Last updated