L2Β·Control & Collections

πŸ”€if / elif / else

Branching on conditions.

ifelifelsematch

Β§ 1Basic branching

Python uses indentation to define blocks β€” no braces.

Β§ 2Ternary expression

value_if_true if condition else value_if_false

Β§ 3match/case (3.10+)

Pattern matching for structural dispatch. Not a switch β€” patterns bind names and destructure.

Animated step-through

step 1 / 5
1score = 87​
2if score >= 90:​
3 grade = 'A'​
4elif score >= 80:​
5 grade = 'B'​
6else:​
7 grade = 'C'​
8print(grade)​
Variables
score→87

Try it live Β· Python runs in your browser

Loading playground…

Checkpoint quiz

Question 1 / 2
How do you write a one-line conditional?