← Python Programming learning pathPython Programming · Module 4 of 10
Conditions: if, elif, else
Make decisions in code with if, elif and else.
📖 Key ideas
- if runs a block only when its condition is True.
- elif checks another condition if the earlier ones were False.
- else runs when no condition matched.
- Conditions can combine with and, or, not.
- Only one branch of an if/elif/else chain runs.
💡 Real-life example: A traffic signal: if red, stop; elif yellow, slow down; else go.
ifRuns a block when a condition is True
elifChecks another condition
elseRuns when nothing else matched
ConditionExpression that is True or False