Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Selection

Match Case

All topicsPractise exam questions
Knowledge organiser

Selection

301.9d

Match Case statements

What you need to know

Python 3.10 introduced match-case (structural pattern matching). It compares a value against multiple patterns, similar to a switch statement in other languages.

Key points

  • match value: starts the block
  • case pattern: checks if value matches
  • case _: is the default (wildcard) case
  • Cleaner than long elif chains for simple value matching
  • Available from Python 3.10 onwards

Code examples

Match Case
python
command = input("Enter command: ")
match command:
    case "start":
        print("Starting...")
    case "stop":
        print("Stopping...")
    case _:
        print("Unknown command")