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:
# codeExample
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.
