Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why isn there a switch or case statement in Python?

Case Python Switch
0
10 Posted

Why isn there a switch or case statement in Python?

0

You can do this easily enough with a sequence of if… elif… elif… else. There have been some proposals for switch statement syntax, but there is no consensus (yet) on whether and how to do range tests. See PEP 275 for complete details and the current status. For cases where you need to choose from a very large number of possibilities, you can create a dictionary mapping case values to functions to call.

0

You can do this easily enough with a sequence of if and elif statements. There have been some proposals for switch statement syntax, but there is no consensus (yet) on whether and how to do range tests, and more importantly, when and how to evaluate constant case expressions. See PEP 275 for some background. For cases where you need to choose from a very large number of possibilities, you can create a dictionary mapping case values to functions to call.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123