Curriculum / Python / Lesson 06

Conditions (if / elif / else) in Python

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

6 of 11
beginner 📖 5 min read 🎯 1 question

Conditions

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

💡 Key insight Python has no switch statement in most versions; match-case syntax (Python 3.10+) is a newer alternative worth knowing about.

Syntax

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

Example

Notice there are no curly braces — the indentation itself defines which lines belong to each block.

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

Try it yourself

Copy this example into the Python compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What keyword does Python use instead of 'else if'?

Back to curriculum