Introduction
Conditional statements let your program make decisions. Python uses if, elif, and else — and indentation instead of curly braces.
If statements
age = 20
if age >= 18:
print("You are an adult.")
elif age >= 13:
print("You are a teenager.")
else:
print("You are a child.")
# Ternary (conditional expression)
status = "adult" if age >= 18 else "minor"
# Match statement (Python 3.10+)
command = "start"
match command:
case "start":
print("Starting...")
case "stop":
print("Stopping...")
case _:
print("Unknown command")Important: Python uses indentation (4 spaces) to define code blocks. This is not optional — it's part of the language syntax.
Assignment
- Read about control flow in Python.
- Write a program that asks the user for a number and prints whether it's positive, negative, or zero.
- Experiment with the match statement if you have Python 3.10+.