For those who haven't dug in yet, I can thoroughly recommend Raymond Hettinger's video on structural pattern matching - great content, and also explains some of the unexpected aspects. Answer from Enmeshed on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-match-case-statement
Python Match Case Statement - GeeksforGeeks
December 11, 2025 - In this example, the function check_number(x) uses a match-case statement to compare the value of x to the constants 10 and 20. If x equals 10, it prints "It's 10". If x equals 20, it prints "It's 20". If neither condition is met, the wildcard _ matches any value, leading to the message "It's neither 10 nor 20". Let's take a look at python match case statement in detail:
🌐
W3Schools
w3schools.com › python › python_match.asp
Python Match
Instead of writing many if..else statements, you can use the match statement. The match statement selects one of many code blocks to be executed. match expression: case x: code block case y: code block case z: code block
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
December 11, 2025 - This use has no special meaning ... as well. See The Ellipsis Object. A match statement takes an expression and compares its value to successive patterns given as one or more case blocks....
🌐
Reddit
reddit.com › r/learnpython › is it "right" to use the match/case statement rather than if/else when you just want to check certain conditions?
r/learnpython on Reddit: Is it "right" to use the match/case statement rather than if/else when you just want to check certain conditions?
December 11, 2024 -

I can't say I fully understand the match/case statement yet, but I know a part of it involves more than just simple pattern matching. I know that the expression in the match statement, for example, actually runs and creates a result, such as an object if it's a call to a class.

So I'm wondering, if I don't want to do all that and just want to use it as a cleaner version of if/else, is this considered Pythonic, or is it overkill?

For example:

if some_value == True and some_other == 1:
    do something
elif some_value == False and some_other == 1:
    do something else
etc etc etc

or:

match (some_value, some_other):
    case (True, 1):
        do something
    case (False, 1):
        do something else
    etc etc etc

First off, I *think* I'm getting the syntax correct! Second, I'm not actually creating any values with the expressions, so it feels like a glorified if/else construct, just cleaner looking.

Is this a valid use of match/case?

Thanks!

🌐
Reddit
reddit.com › r/python › opinions on match-case?
r/Python on Reddit: Opinions on match-case?
February 12, 2025 -

I am curious on the Python community’s opinions on the match-case structure. I know that it has been around for a couple of years now, but some people still consider it relatively new.

I personally really like it. It is much cleaner and concise compared if-elif-else chains, and I appreciate the pattern-matching.

match-case example:

# note that this is just an example, it would be more fit in a case where there is more complex logic with side-effects

from random import randint

value = randint(0, 2)

match value:
    case 0:
        print("Foo")
    case 1:
        print("Bar")
    case 2:
        print("Baz")
🌐
GitHub
github.com › github › spec-kit › issues › 1718
[Feature]: Context Auto-Discovery from team-ai-directives using grep-based search · Issue #1718 · github/spec-kit
6 days ago - # Extract keywords from feature description keywords=$(echo "$feature_description" | tr '[:upper:]' '[:lower:]' | ...) # Search team-ai-directives for keyword in $keywords; do grep -ril "$keyword" "$team_directives_path" >> results done # Rank by match frequency, categorize by type # Output: constitution, personas[], rules[], skills[], examples[] Input: /spec.specify Implement OAuth2 authentication for Python FastAPI Grep finds: - senior_python_developer.md (3 matches: oauth, python, fastapi) - prevent_sql_injection.md (2 matches: oauth, authentication) - python_testing.md (1 match: python) Output in context.md: - Constitution: context_modules/constitution.md - Persona: context_modules/personas/senior_python_developer.md - Rules: security/prevent_sql_injection.md, testing/python_testing.md ·
Published   Feb 27, 2026
🌐
Python.org
discuss.python.org › ideas
Allow matching `callable()` in match-case statements - Ideas - Discussions on Python.org
June 3, 2024 - Currently, there is no way to match an object in a match-case statement if it is callable. This leads to ugly remainder-cases: match thing: case SomeValueType(): ... case type() as constructor: .…
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › conditional-statements-in-python
Conditional Statements in Python - GeeksforGeeks
number = 2 match number: case 1: print("One") case 2 | 3: print("Two or Three") case _: print("Other number")
Published   October 8, 2025
🌐
Reddit
reddit.com › r/learnprogramming › what's a meaningful difference between match-case and a bunch of if statements?
r/learnprogramming on Reddit: What's a meaningful difference between match-case and a bunch of if statements?
January 2, 2024 -
if parameter == a:
    do a's stuff
if parameter == b:
    do b's stuff
if parameter == c:
    do c's stuff

vs.

match parameter:
    case a:
        do a's stuff
    case b:
        do b's stuff
    case c:
        do c's stuff.

If anything, it just seems like match is just one line longer. I suppose you don't have to write "parameter ==" every time. But that doesn't seem very important.

Top answer
1 of 8
7
In Python, one primary difference is that match-case supports some syntax that if doesn't - it doesn't just test equality, you can match elements in a list, elements in a dictionary, and more. In cases where the if and match have equal power, using match-case can help readability for other programmers. Programmers reading it can look at a glance and know that at most one case will match; they don't have to carefully look to make sure every since if has an "else/elif" or other surprises. Also, this applies more to compiled languages than Python, but writing a match-case or switch-case is actually a powerful optimization signal. While if statements must be executed in order, the order of case statements doesn't matter. The compiler can often take a large switch-case and find a way to execute it far more quickly than testing each possibility one at a time. While I don't believe Python takes advantage of this today, it certainly could in the future.
2 of 8
2
It depends on the language. I don't use switch in C-like languages because the default behavior of switch is to "fall through" when most programmers use "break" as in switch (expression) { case 1: doCase1(); break; case 2: doCase2(); break; } The break is the one that's used most often, so it should be the default behavior, and a new keyword like fallthrough should be used in the rare case that you want to run the code in the next statement. Some languages allow for conditions instead of exact match in the case statement. In any case, I hardly see switch statements and I pretty much never use it.
Top answer
1 of 2
73

Rather than match type(v), match v directly:

values = [
    1,
    "hello",
    True,
]

for v in values:
    match v:
        case str():
            print("It is a string!")
        case bool():
            print("It is a boolean!")
        case int():
            print("It is an integer!")
        case _:
            print(f"It is a {type(v)}!")

Note that I've swapped the order of bool() and int() here, so that True being an instance of int doesn't cause issues.

This is a class pattern match.

2 of 2
11

You can match directly against the type of v, but you need a value pattern to refer to the types to match, as a "dotless" name is a capture pattern that matches any value. For example,

import builtins


values = [
    1,
    "hello",
    True
]

# Caveat: this will continue to work even if someone
# rebinds the built-in, but not, for example, if builtins.str
# itself is rebound.
for v in values:
    match type(v):
        case builtins.str:
            print("It is a string!")
        case builtins.int:
            print("It is an integer!")
        case builtins.bool:
            print("It is a boolean!")
        case _:
            print(f"It is a {type(v)}!")

Note that a value pattern must be a dotted name; it's not an arbitrary expression that can evaluate to a specific value.

(Whether you really want to match against the actual type of a value, or really want to determine if a value is an instance of a given type, is another matter. In the latter case, an if-elif statement is needed.

if isinstance(v, bool):
    print("It is a boolean!")
elif isinstance(v, int):
    print("It is an int!")
elif isinstance(v, str):
    print("It is a string!")
else:
    print(f"It is a {type(v)}!")

There is no pattern that lets you use the result of calling isinstance as the case to match against. )

🌐
Python
peps.python.org › pep-0636
PEP 636 – Structural Pattern Matching: Tutorial | peps.python.org
This is called matching · It will bind some names in the pattern to component elements of your subject. In this case, if the list has two elements, it will bind action = subject[0] and obj = subject[1].
🌐
Python.org
discuss.python.org › ideas
Use "case else" instead of "case _" in match statement - Ideas - Discussions on Python.org
September 16, 2024 - UPD: Probably it not worth it. Rationale Wildcard pattern case _ treats legal variable name _ specially (soft keyword). Syntax case _ has readability issues. It would be much readable if keyword else appear somewhere. Proposed syntax case else with if guard denied.
🌐
Real Python
realpython.com
Python Tutorials – Real Python
Quizzes & Exercises Practice and evaluate your Python knowledge
🌐
Python.org
discuss.python.org › python help
Match/case syntax - Python Help - Discussions on Python.org
October 24, 2022 - In the dark ages when I used to code in vbScript I found this form of the select/case to be clearer than repeated if/else if blocks. I there a form of the new match/case in Python that accomplishes the same thing? I am aware that there are easier ways of coding this particular example but the beauty of this form is that the conditions in the case clauses do not have to be related. select case True case distance
🌐
Python documentation
docs.python.org › 3 › whatsnew › 3.10.html
What’s New In Python 3.10
Specifically, pattern matching operates by: ... comparing the subject with each pattern in a case statement from top to bottom until a match is confirmed.
🌐
SkillVertex
skillvertex.com › blog › python-match-case-statement
Python Match-Case Statement
March 19, 2024 - Python match statement began in Python 3.10 and offers user experience, good readability, and cleanliness in the code. The pattern matching technique in Python 3.10 is known as match-case.
🌐
Readthedocs
pc-python.readthedocs.io › en › latest › python_advanced › match_case.html
6. Match - Case — PC-Python
Python refers to this as structural pattern matching. Match-case statements can be used for what is known as switch-case statements in general use in other languages.
🌐
Python Morsels
pythonmorsels.com › match-case-parsing-python
Appreciating Python's match-case by parsing Python code - Python Morsels
June 22, 2022 - Python's match-case blocks are complex structural pattern matching tools that are often more hassle than they're worth. But they're great for parsing abstract syntax trees.
🌐
Mimo
mimo.org › glossary › python › match-statement
Python Match Statement: A Versatile Switch-Case in Python
You can use the equivalent of the switch-case statement in Python to simplify complex conditionals. Instead of using multiple if-elif statements, you can use cases to check against. ... def http_status_code(status): match status: case 200: return "OK" case 404: return "Not Found" case 500: ...
🌐
Python.org
discuss.python.org › python help
Python 3.10: match-case syntax for catching exceptions - Python Help - Discussions on Python.org
October 11, 2021 - I am playing with this new match-case syntax in Python 3.10 and I had a thought whether one would be able to catch exceptions with it. Is it possible? Let’s take a look! >>> def say(something): ... match something: ... case "hello": ... print("Hello to you!") ... case TypeError: ... print("Uhm, what was that you said?!") ... >>> say(123) Uhm, what was that you said?!