You can define a default case in Python. For this you use a wild card (_). The following code demonstrates it:

x = "hello"
match x:
    case "hi":
        print(x)
    case "hey":
        print(x)
    case _:
        print("not matched")
Answer from Prince Hamza on Stack Overflow
🌐
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
The value _ will always match, so it is important to place it as the last case to make it behave as a default case.
Discussions

Use "case else" instead of "case _" in match statement - Ideas - Discussions on Python.org
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. More on discuss.python.org
🌐 discuss.python.org
1
September 16, 2024
Opinions on match-case?
Match-case is great for structural pattern matching (which is what it's designed for) but you cannot just replace any and all if statements with match-case. So while the match-case might be more readable in itself, if you blindly go and switch if-else statements to match-case where you can, your code as a whole will become less readable because it keeps jumping from one control flow method to another. So I use match-case in specific cases where I need to match some specific structural pattern, but in most cases I feel it's better to stick with your regular if-else. More on reddit.com
🌐 r/Python
62
16
February 12, 2025
Is it "right" to use the match/case statement rather than if/else when you just want to check certain conditions?
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. More on reddit.com
🌐 r/learnpython
18
7
December 11, 2024
Naming of the match default case
It’s somewhat incorrect to think of the case _ as the default case… it’s the wildcard case, accepting any structure but not binding it to a name… case default would accept any structure and bind it to the name “default”. In effect you choose your poison for the default path: do you care to capture and name, in which case there may be many more semantically useful names than “default”, or do you not care to capture, in which case “default” adds very little more semantic value than case _? And adding that small (and kind of debatable, as the underscore is used in quite a few languages from which match expressions were drawn) semantic value would require the addition of a new keyword to the language, which shouldn’t be done trivially, especially when it would be a keyword that would simply be an alias for case _ since you would still need to have the wildcard for when you want to work with, but not capture, structures (ie case (_, _, True)). I’m not super happy with match syntax, as it’s pretty noisy — Rust’s approach is much cleaner, but can be so by virtue of it being an expression-based language rather than a statement-based one — but because you do want the choice to capture, or not, in the final case I don’t think a dedicated default would really help. More on reddit.com
🌐 r/Python
10
9
June 14, 2021
🌐
Stackademic
blog.stackademic.com › python-match-case-statement-63d01477e1c0
Python Match-Case Statement. Starting from Python 3.10, the Python… | by Caner Uysal | Stackademic
June 12, 2024 - You can use _ to specify a default case when the patterns don't match exactly. The match statement allows you to handle more complex scenarios by specifying additional conditions, dealing with nested patterns, and performing different actions ...
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
December 11, 2025 - For this last case, many people use the ellipsis literal ... instead of pass. This use has no special meaning to Python, and is not part of the language definition (you could use any constant expression here), but ... is used conventionally as a placeholder body 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.
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
4 days ago - The U flag still exists for backward compatibility, but is redundant in Python 3 since matches are Unicode by default for str patterns, and Unicode matching isn’t allowed for bytes patterns. UNICODE and the inline flag (?u) are similarly redundant. ... Display debug information about compiled expression. No corresponding inline flag. ... Perform case-insensitive matching; expressions like [A-Z] will also match lowercase letters.
🌐
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.
Find elsewhere
🌐
Plain English Westminster
benhoyt.com › writings › python-pattern-matching
Structural pattern matching in Python 3.10
Python evaluates the match expression, and then tries each case from the top, executing the first one that matches, or the _ default case if no others match.
🌐
DataCamp
datacamp.com › tutorial › python-switch-case
Python Switch Case Statement: A Beginner's Guide | DataCamp
December 6, 2024 - case "Saturday" | "Sunday": Matches any of the listed patterns. The | symbol acts like an OR operator. case _: A catch-all (default) case to handle invalid inputs. No break Needed: Unlike traditional switch-case, Python exits the match block after the first successful match.
🌐
Mimo
mimo.org › glossary › python › match-statement
Python Match Statement: A Versatile Switch-Case in Python
match expression: case pattern1: # Execute if pattern1 fits case pattern2: # Execute if pattern2 fits case _: # Execute if no pattern fits (default case) match: The keyword to initiate a switch-case statement in Python.
🌐
Python Morsels
pythonmorsels.com › match-case-parsing-python
Appreciating Python's match-case by parsing Python code - Python Morsels
June 22, 2022 - Python 3.10 added a match-case block that folks often assume to be equivalent to the switch-case blocks from other programming languages. While you can use match-case like switch-case, you usually wouldn't: match-case is both more powerful and more complex than switch-case.
🌐
Tutorialspoint
tutorialspoint.com › home › python › python match case statement
Python Match Case Statement
February 21, 2009 - A Python match-case statement takes an expression and compares its value to successive patterns given as one or more case blocks. Only the first pattern that matches gets executed.
🌐
Analytics Vidhya
analyticsvidhya.com › home › what is match case statement in python?
What is Match Case Statement in Python? - Analytics Vidhya
May 29, 2024 - The syntax of the match case statement in Python is as follows: match expression: case pattern1: # code block for pattern1 case pattern2: # code block for pattern2 ... case patternN: # code block for patternN case _: # default code block
🌐
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")
🌐
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!

🌐
Programiz PRO
programiz.pro › resources › python-match-case
Python match case Statement
December 10, 2024 - Note: You can use _ instead of other as a default case as: ... number = 48 match number: case 29: print('Small') case 42: print('Medium') case 44: print('Large') case 48: print('Extra Large') case other: print('Unknown') # Output: Extra Large · Here, the value of number matches case 48:, so the associated code is executed. Python match...case allows tuples in cases, enabling structured pattern matching.
🌐
The Teclado Blog
blog.teclado.com › python-match-case
Using "match...case" in Python 3.10
October 26, 2022 - If a comparison expression doesn’t match with anything else, it will always match with the _ case. Any cases below this case will never run because all cases will match with the underscore case.
🌐
Medium
techytales.medium.com › pythons-switch-statement-a-beginner-s-guide-4aaffef29cb5
Python’s Alternative for Switch Statement: A Beginner’s Guide for match case statement | by Nihal Patel | Medium
June 21, 2023 - If it matches, the code inside this case block executes, which is print("fruit is orange."). It will display the message "fruit is orange." case _:, the underscore _ acts as a placeholder for the default case, which matches any value that didn't ...
🌐
freeCodeCamp
freecodecamp.org › news › python-switch-statement-switch-case-example
Python Switch Statement – Switch Case Example
August 5, 2022 - match term: case pattern-1: action-1 case pattern-2: action-2 case pattern-3: action-3 case _: action-default · Note that the underscore symbol is what you use to define a default case for the switch statement in Python.