Python 3 Tutorial · Chapter 12 of 22
Python Match
Choose from fixed menu options with match/case.
Python 3.10+ match/case is the classroom equivalent of switch.
Use case _ as the default branch for invalid input.
Match/case sample
Try it Yourself »
choice = int(input("1. Add\n2. Subtract\nChoose: "))
match choice:
case 1:
print("Addition selected")
case 2:
print("Subtraction selected")
case _:
print("Invalid choice")
Classroom Tips
- Always include a default case for invalid input.