Notes / Python / Conditions

Conditions (if / elif / else) in Python — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Conditions Python conditionals use if, elif (short for "else if"), and else — with indentation, not curly braces, marking each block..

Syntax

syntax
if condition:
    # code
elif condition2:
    # code
else:
    # code

Example

py
marks = 72
if marks >= 90:
    print("Grade: A")
elif marks >= 60:
    print("Grade: B")
else:
    print("Grade: C")

Output

outputGrade: B

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Be ready to explain why Python enforces indentation strictly — it removes ambiguity about which block a line belongs to, at the cost of being whitespace-sensitive.
Back to notes Read full lesson →