What keyword introduces a pattern matching block in Python 3.10?

The story behind the answer

In Python 3.10, the match keyword introduces a structural pattern-matching block.

A match statement evaluates a subject expression and tests it against successive patterns written in case clauses. The first matching case runs, and patterns can do more than compare literal values: they can unpack sequences, inspect mappings, recognize classes, and bind parts of a value to names. This gives Python a concise way to branch on both data and structure.

Python’s syntax resembles switch statements found in languages such as C, Java, and JavaScript, but match is more expressive than a simple value-based switch. The optional case _ pattern acts as a wildcard and is similar to a default branch. A case may also include a guard, such as if score > 0, to add a condition after the pattern matches.

One subtle detail is that match and case are soft keywords. They have special meaning in pattern-matching syntax but are not treated as permanently reserved identifiers in every context. Structural pattern matching was specified through PEP 634 and released with Python 3.10 on October 4, 2021.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: