match Pattern matching
Last updated: 2026-09-22
match Pattern matching
match subject matches subject against case patterns.
| Category | Keywords & Statements |
|---|---|
| Kind | Keyword / Statement |
| Python Version | 3.10+ |
📝 Syntax
match subject:
case pattern:
block
case pattern:
block
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
greeting
🏷️ Related Keywords / Statements
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat Python version does `match` require?
APython 3.10 or later (PEP 634/635). On 3.9 and below it raises `SyntaxError`; you need to upgrade Python, or temporarily replace it with an `if`/`elif` chain.
QWhat is the difference between `match` and an `if`/`elif` chain?
A`match` performs structural pattern matching: it can match literals, destructure tuples/lists/dicts (`case (0, y)`), combine patterns with `|`, and use `_` as fallback — clearer than a long `if`/`elif` chain.
QWhat does `case _` mean?
A`_` is a wildcard that matches any value, acting as an `else` fallback. It usually goes in the last `case` and handles everything not matched by the earlier patterns.