Python Foundations · Lesson 4 of 12Selection with if
Conditions, comparisons and if/elif/else. Learn through short examples, practical tasks and targeted questions.
← All lessons
Making decisions with if
Selection allows a program to take different paths depending on a condition. Python uses if, elif and else, with indentation showing which statements belong to each branch. Try values at either side of a threshold and exactly on the boundary.
Watch out: A single = assigns a value; == compares values. Confusing them causes errors in conditional expressions.
A free TutorSyntax programming lesson. About our teaching approach.
APPLY THE IDEA
Use this skill beyond the example
Trace the condition first, deciding whether it is True or False before following either branch. Test values immediately below, equal to and above the boundary: those are the values most likely to expose mistakes.
Quick check: Which branch runs when score is exactly 50 in if score >= 50?
Check: The if branch runs because >= includes equality.
Continue with related practice →