One of the things I missed when I first started working with Python was the traditional switch case statement that I had used in other programming languages like C and Java.
In Python, there is no built-in switch case, but over the years, I’ve discovered multiple ways to achieve the same functionality. These methods are simple, flexible, and once you understand them, you’ll never feel like you’re missing a switch case again.
In this tutorial, I will show you how to use switch case in Python with user input using practical examples. I will cover five different methods that I personally use depending on the project.
The examples are easy to follow, and I’ll keep them close to real-world scenarios so that you can apply them directly in your own projects.
Why Switch Case is Missing in Python
Unlike many other languages, Python emphasizes readability and simplicity. The creators of Python decided not to include a dedicated switch case statement.
Instead, Python developers use alternatives like dictionaries, if-elif chains, functions, and the new match-case statement introduced in Python 3.10.
Now, let’s go step by step and see how we can handle switch case with user input in Python.
Method 1 – Use If-Elif-Else Statements in Python
The easy way to mimic a switch case in Python is by using if-elif-else. This method is beginner-friendly and works in all versions of Python.
choice = input("Enter a state abbreviation (CA, TX, NY): ")
if choice == "CA":
print("You selected California - The Golden State")
elif choice == "TX":
print("You selected Texas - The Lone Star State")
elif choice == "NY":
print("You selected New York - The Empire State")
else:
print("Invalid state abbreviation entered.")I have executed the above example code and added the screenshot below.

Here, I am asking the user to enter a state abbreviation (a real-world example for the USA). Based on the input, the program prints a state-specific message.
Method 2 – Use Python Dictionary Mapping
When I want my code to be cleaner and more efficient, I prefer using a dictionary mapping. This approach is more “Pythonic” and is widely used by experienced developers.
def get_state_info(state):
states = {
"CA": "California - The Golden State",
"TX": "Texas - The Lone Star State",
"NY": "New York - The Empire State"
}
return states.get(state, "Invalid state abbreviation entered.")
choice = input("Enter a state abbreviation (CA, TX, NY): ")
print(get_state_info(choice))I have executed the above example code and added the screenshot below.

Here, the dictionary acts as a switch case. The .get() method also lets me define a default response for invalid input. This method is compact and much easier to maintain compared to multiple if-elif statements.
Method 3 – Use Functions with a Python Dictionary
Sometimes, I want to execute different functions based on user input instead of just returning a string. In that case, I map functions to dictionary keys.
def california():
return "Welcome to California! Famous for Silicon Valley and Hollywood."
def texas():
return "Welcome to Texas! Known for BBQ and wide-open spaces."
def new_york():
return "Welcome to New York! The city that never sleeps."
def invalid():
return "Invalid state abbreviation entered."
switch = {
"CA": california,
"TX": texas,
"NY": new_york
}
choice = input("Enter a state abbreviation (CA, TX, NY): ")
print(switch.get(choice, invalid)())I have executed the above example code and added the screenshot below.

This method is powerful because each case can run a complete function with multiple lines of logic. I use this approach when I need to perform more than just printing a message.
Method 4 – Use Match-Case (Python 3.10 and Above)
Starting from Python 3.10, we finally have a built-in match-case statement. This is the closest thing to a traditional switch case in Python.
choice = input("Enter a state abbreviation (CA, TX, NY): ")
match choice:
case "CA":
print("California - Technology hub and beautiful beaches.")
case "TX":
print("Texas - Big skies and southern hospitality.")
case "NY":
print("New York - Financial capital of the USA.")
case _:
print("Invalid state abbreviation entered.")I have executed the above example code and added the screenshot below.

This syntax is clean, readable, and feels very natural if you are coming from other languages. If you are using Python 3.10 or later, I strongly recommend this method.
Method 5 – Use Lambda Functions
Another advanced way I sometimes use is with lambda functions inside a dictionary. This method is concise and works well for small one-line operations.
switch = {
"CA": lambda: "California - Known for innovation and wine country.",
"TX": lambda: "Texas - Home to NASA and cowboy culture.",
"NY": lambda: "New York - The cultural capital of the USA."
}
choice = input("Enter a state abbreviation (CA, TX, NY): ")
print(switch.get(choice, lambda: "Invalid state abbreviation entered.")())This is a neat trick when I want compact switch-like functionality without defining multiple functions.
Which Method Should You Use?
If you are a beginner, start with if-elif-else.
- For cleaner code, use dictionary mapping.
- If you need to call multiple lines of logic, go with functions in a dictionary.
- If you are on Python 3.10+, the match-case statement is the best choice.
- For short cases, lambda functions work perfectly.
I have been working with Python, and I can confidently say that not having a built-in switch case has never been a limitation.
Python gives us multiple flexible ways to implement switch case behavior. Whether you are handling user input for state abbreviations, menu-driven programs, or command-line utilities, you can choose the method that best fits your project.
I hope you found this tutorial helpful. Try out these methods in your own Python projects, and you’ll quickly see which one feels most natural to you.
You may also read:
- Python Copy Dict Without One Key
- Convert a Dict to String in Python
- Python Nested Dictionary to JSON
- Remove Empty Keys From a Dictionary in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.