1. The if-elif-else Ladder
Mutually Exclusive Evaluation
- Conditions are evaluated sequentially from top to bottom.
- The first condition that evaluates to Truthy executes its block, and Python skips all remaining elif and else clauses.
- An else clause executes only if all preceding if and elif tests evaluated to falsy.
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(f"Score {score} -> Grade {grade}")
💡 Key Takeaway: Place the most specific conditions at the top of the elif ladder.