← All notes

Match a subject value with a Python case pattern

Answer: The match statement is used for pattern matching. It was added in version 3.10. PEP 634 provides the technical specification for the match statement. It replaces PEP 622, which was split into PEP 634 (specification), PEP 635 (motivation), and PEP 636 (tutorial).

Subject and cases

Pattern matching takes a pattern as input (following case) and a subject value (following match). Subpatterns are allowed in the pattern. The outcomes are a match success or failure, and possible binding of matched values to a name. The match and case keywords are soft keywords.

Reading the spec

PEP 634 is intentionally devoid of commentary; the motivation and design choices are in PEP 635. Use one match on the subject, then one or more case blocks.

| match | case | |---|---| | match statement | Used for pattern matching, added in 3.10 | | subject value | Follows match | | pattern | Follows case, may contain subpatterns | | soft keywords | match and case |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 634 – Structural Pattern Matching: Specification; Python docs, Compound statements. Public-Domain; PSF-2.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 634 – Structural Pattern Matching: Specification; Python docs, Compound statements. Public-Domain; PSF-2.0.

Cite this

Permanent ID: iil:note:hacq2n0w

iinventedlight. 2026. "Match a subject value with a Python case pattern." iinventedlight Library, iil:note:hacq2n0w, version of 2026-11-19. https://iinventedlight.com/library/notes/pep-634-structural-pattern-matching/. License: CC-BY-4.0.

@misc{iil_note_hacq2n0w,
  author = {{iinventedlight}},
  title = {{Match a subject value with a Python case pattern}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/pep-634-structural-pattern-matching/},
  note = {Permanent ID iil:note:hacq2n0w. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pep-634-structural-pattern-matching.md.