Conditional Statements (if, elif, else)
Every program eventually needs to do different things depending on a value. Python uses if, elif (short for "else if"), and else for this — and instead of curly braces, it uses indentation to mark what belongs inside each block.
age = 20
if age >= 18:
print("You are an adult")
else:
print("You are a minor")You are an adult
That indentation isn't just a style choice — it's how Python knows what belongs inside the if block. Get it wrong (mix tabs and spaces, or indent inconsistently) and you'll get a real IndentationError, not a silent bug.
Chaining conditions with elif
score = 75
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
else:
print("F")C
Python checks each condition top to bottom and stops at the first one that's true — score >= 70 matches before it ever reaches else, so "C" is printed and everything after is skipped.
Next: for loops — repeating code over every item in a collection.
Practice exercise
Set age = 16. Print "Minor" if age is less than 18, otherwise print "Adult".