This is documented under Structural Pattern Matching

Like unpacking assignments, tuple and list patterns have exactly the same meaning and actually match arbitrary sequences. Technically, the subject must be a sequence. Therefore, an important exception is that patterns don’t match iterators. Also, to prevent a common mistake, sequence patterns don’t match strings.

and in PEP 635 -- Structural Pattern Matching: Motivation and Rationale

As in iterable unpacking, we do not distinguish between 'tuple' and 'list' notation. [a, b, c], (a, b, c) and a, b, c are all equivalent. While this means we have a redundant notation and checking specifically for lists or tuples requires more effort (e.g. case list([a, b, c])), we mimic iterable unpacking as much as possible.

Answer from user459872 on Stack Overflow
🌐
Plain English Westminster
benhoyt.com › writings › python-pattern-matching
Structural pattern matching in Python 3.10
I’ve opened an issue and a pull request that adds a test case for this and fixes the bug. Django has 327,000 lines of code, including tests. Of these, there are 905 uses of elif, or 0.3%. Example from Django admin checks, in _check_fieldsets_item(). The structural matching is great here, but doesn’t help produce good error messages. def _check_fieldsets_item(self, obj, fieldset, label, seen_fields): if not isinstance(fieldset, (list, tuple)): return must_be('a list or tuple', option=label, obj=obj, id='admin.E008') elif len(fieldset) != 2: return must_be('of length 2', option=label, obj=obj, id='admin.E009') elif not isinstance(fieldset[1], dict): return must_be('a dictionary', option='%s[1]' % label, obj=obj, id='admin.E010') elif 'fields' not in fieldset[1]: return [ checks.Error( "The value of '%s[1]' must contain the key 'fields'."
🌐
Python
peps.python.org › pep-0636
PEP 636 – Structural Pattern Matching: Tutorial | peps.python.org
def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's wrong with the Internet" Note the last block: the “variable name” _ acts as a wildcard and never fails to match. You can combine several literals in a single pattern using | (“or”): ... # point is an (x, y) tuple match point: case (0, 0): print("Origin") case (0, y): print(f"Y={y}") case (x, 0): print(f"X={x}") case (x, y): print(f"X={x}, Y={y}") case _: raise ValueError("Not a point")
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-match-case-statement
Python Match Case Statement - GeeksforGeeks
December 11, 2025 - The match-case statement is particularly powerful when working with sequences such as lists or tuples.
🌐
Python
peps.python.org › pep-0622
PEP 622 – Structural Pattern Matching | peps.python.org
Like unpacking assignment, both tuple-like and list-like syntax can be used, with identical semantics. Each element can be an arbitrary pattern; there may also be at most one *name pattern to catch all remaining items: match collection: case 1, [x, *others]: print("Got 1 and a nested sequence") case (1, x): print(f"Got 1 and {x}")
🌐
Datamentor
datamentor.io › python › match-case
Python match...case Statement (With Examples)
plot1 = (0, 4) match plot1: case (4,0): print('on x-axis') case (0,4): print('on y-axis') case (0,0): print('center') # Output: on y-axis · In the above example, we have created a tuple named plot1 with values: 0 and 4.
🌐
Readthedocs
pc-python.readthedocs.io › en › latest › python_advanced › match_case.html
6. Match - Case — PC-Python
Python match-case statements can be used to check the types of something being passed in. In the code below, lists [ ], tuples ( ) and sets { } are distinguished.
🌐
Medium
medium.com › @muhammadshafey063 › python-match-cases-and-their-types-with-uses-0cf2f54cc730
Python: Match cases and their types with uses | by Muhammad shafey | Medium
June 1, 2024 - Matches a value against a single pattern. match x: case 1: print(“x is 1”) case 2: print(“x is 2”) ... A simple match case statement that matches the value of x against the patterns 1 and 2. Matches a tuple against multiple patterns.
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_match.asp
Python Match
month = 5 day = 4 match day: case 1 | 2 | 3 | 4 | 5 if month == 4: print("A weekday in April") case 1 | 2 | 3 | 4 | 5 if month == 5: print("A weekday in May") case _: print("No match") Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Python Engineer
python-engineer.com › posts › pattern-matching-python
Master Pattern Matching In Python 3.10 | All Options | - Python Engineer
def http_error(status): match status: case 400: return "Bad request" case _: return "Something's wrong with the internet" Patterns can look like unpacking assignments, and a pattern may be used to bind variables. In this example we match a tuple here, and the data point can be unpacked to its x- and y-coordinate.
🌐
LWN.net
lwn.net › Articles › 828486
"Structural pattern matching" for Python, part 2 [LWN.net]
Either would violate a longstanding expectation in Python, so the authors rejected both possibilities. Larry Hastings wondered about the special treatment being given to the "_" wildcard match. That symbol acts like a regular identifier, except in case statements, where it does not get bound (assigned to) for a match; it can also be used more than once in a case, which is not allowed for other match variables: match x: case (_, _): # match any tuple print(_) # _ will not have a value case (x, x): # ILLEGAL
🌐
LearnPython.com
learnpython.com › blog › python-match-case-statement
How to Use a match case Statement in Python 3.10 | LearnPython.com
This is Python 3.10’s most important new feature; the new functionality allows you to more easily control the flow of your programs by executing certain parts of code if conditions (or cases) are met. In this article, we’ll tell you everything you need to know about the match case statement in Python, which will allow you to have fine-grained control over how your programs execute.
🌐
Turingtaco
turingtaco.com › pattern-matching-lists-and-dictionaries-in-python
Pattern Matching Lists and Dictionaries in Python
December 7, 2024 - For example, in a pattern like case (a, *b), a matches the first element of the input tuple, while b captures the rest as another tuple. This feature allows for flexible matching of variable elements within a tuple, similar to how it works with ...
🌐
Python Morsels
pythonmorsels.com › match-case-parsing-python
Appreciating Python's match-case by parsing Python code - Python Morsels
June 22, 2022 - Matching a list or tuple of length N involves writing a list of length N. And in my case, matching an abstract syntax tree involves writing code that looks like an abstract syntax tree.
🌐
AlgoMaster
algomaster.io › learn › python › match-case
Match Case | Python | AlgoMaster.io | AlgoMaster.io
When working with lists or tuples, you can match on their structure directly. For example: In this example, we destructure the coord variable directly within the case statements.
🌐
Python
typing.python.org › en › latest › spec › tuples.html
Tuples — typing documentation
def func(subj: tuple[int | str, int | str]): match subj: case x, str(): reveal_type(subj) # tuple[int | str, str] case y: reveal_type(subj) # tuple[int | str, int] The tuple class derives from Sequence[T_co] where T_co is a covariant (non-variadic) type variable.
🌐
Programiz PRO
programiz.pro › resources › python-match-case
Python match case Statement
Python match...case allows tuples in cases, enabling structured pattern matching.
🌐
Enterprise DNA
blog.enterprisedna.co › python-match-case
Python Match Case: What It Is & How To Use It – Master Data Skills + AI
The tuple (0, y) destructures the point, matching any tuple where the first element is 0 (indicating it’s on the Y-axis) and binds the second element to y. The match keyword initiates the match case statement.
🌐
GitHub
github.com › python › mypy › issues › 12364
`mypy` unable to narrow type of tuple elements in `case` clause in pattern matching · Issue #12364 · python/mypy
February 8, 2022 - Bug Report When using match on a tuple, mypy is unable to apply type narrowing when a case clause specifies the type of the elements of the tuple. To Reproduce Run this code through mypy: class MyClass: def say_boo(self) -> None: print("...
Published   Mar 16, 2022