match Statement (Python 3.10+)

The match statement is used for pattern matching and is similar to switch-case in other languages.

🔀 Cleaner alternative to multiple if–elif statements.

Basic Syntax

day = 2

match day:
    case 1:
        print("Monday")
    case 2:
        print("Tuesday")
    case 3:
        print("Wednesday")
    case _:
        print("Invalid day")

Default Case

case _ works as the default option.

Practice

  1. Print weekday name using number
  2. Use match for menu selection