📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Control Flow

Control Flow

4 min read Quiz at the end
Python uses if, elif, and else for decisions. Compare with ==, !=, <, >, and combine with and, or, not. The ternary form: value = 'yes' if condition else 'no' is a clean one-line conditional expression.

if / elif / else

score = 85
if score >= 90:
    grade = "A"
elif score >= 70:
    grade = "B"
else:
    grade = "C"
print(grade)  # B

# One-liner ternary
result = "pass" if score >= 50 else "fail"
Sign in to track your progress.
Topic Quiz · 5 questions

Test your understanding before moving on

1. What is the Python ternary syntax?
💡 Python ternary: value = a if condition else b.
2. Which operator checks equality?
💡 == checks equality in Python. = is assignment.
3. What does "elif" mean?
💡 elif is Python's else if — checked when the previous condition was false.
4. Can you have multiple elif blocks?
💡 You can chain any number of elif blocks.
5. Which keyword checks membership?
💡 The in operator checks membership: if x in list.