← Python Programming learning path
Python Programming · Module 4 of 10

Conditions: if, elif, else

Make decisions in code with if, elif and else.

📖 Key ideas

  1. if runs a block only when its condition is True.
  2. elif checks another condition if the earlier ones were False.
  3. else runs when no condition matched.
  4. Conditions can combine with and, or, not.
  5. 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