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
- id: C1 claim: PEP 634 is the technical specification for the match statement, replacing PEP 622. source: S1 evidence: "the technical specification for the match statement"
- id: C2 claim: The match statement is used for pattern matching and was added in Python 3.10. source: S2 evidence: "The match statement is used for pattern matching"
- id: C3 claim: A pattern is matched against the subject value following match. source: S2 evidence: "Pattern matching takes a pattern as input (following case )"
Sources
- [S1] PEP 634 – Structural Pattern Matching: Specification. Python PEPs. https://peps.python.org/pep-0634/ . License: Public-Domain. Accessed 2026-11-19.
- [S2] Compound statements. Python docs. https://docs.python.org/3/reference/compound_stmts.html . License: PSF-2.0. Accessed 2026-11-19.
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
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.},
}
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.
- pep-634-structural-pattern-matching.table.json (table; CC-BY-4.0)
- pep-634-structural-pattern-matching.schema.json (schema; CC-BY-4.0)
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.