A condition: the program chooses a branch
if tests a condition. If true, its indented block runs; otherwise the else block runs. The operator == compares values, whereas = assigns a value.
| Observation | What it means |
|---|---|
| x = 7; x >= 5 | True: if branch |
| x = 3; x >= 5 | False: else branch |
One worked example
- x = 7The variable holds 7.
- if x >= 5: y = 10 else: y = 207 >= 5 is true.
- y = 10Only the if branch runs.
Watch out: Indentation is structural in Python. Separate if blocks can run several branches; this if/else selects one.
Goal, prerequisites and card origin
What you will learn: Evaluate a simple Python if/else.
What you need first: Variables and numerical comparisons.
An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1
Reference for the underlying principle ↗Show connections
if tests a condition. If true, its indented block runs; otherwise the else block runs. The operator == compares values, whereas = assigns a value.