Why there is no switch-case in python?

how can i use switch-case in python if i dont want to use if-else ladders??

Hi,
In python we don’t have any switch statement. instead we have dictionary, we prefer to use that more often.

Here is one example:

def f(x):
    return {
        'sqr': lambda x: x**2,
        'cub': lambda x: pow(x,3),
    }[x]

f('cub')(3)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Python doesn’t have a switch/case statement because of Unsatisfactory Proposals . Nobody has been able to suggest an implementation that works well with Python’s syntax and established coding style. There have been many proposals, some of which you can see in PEP 3103 – A Switch/Case Statement .

You can use for example a dict:

def get_weekday_number(day):
    """
    The function returns the number of weekday for given day.
    Lower case and upper case are allowed.
    """
    days = {
        'Friday': 4,
        'Monday': 0,
        'Saturday': 5,
        'Sunday': 6,
        'Thursday': 3,
        'Tuesday': 1,
        'Wednesday': 2,
        }
    return days[day.title()]