I'm wondering why python does not supporting Switch case? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I'm wondering why python does not supporting Switch case?

11th Jun 2021, 2:30 PM
XXSH_
XXSH_ - avatar
5 Answers
+ 9
It does now. But with a different name, match-case. https://www.python.org/dev/peps/pep-0622/
11th Jun 2021, 2:33 PM
Nikhil
Nikhil - avatar
+ 3
If you're using a version of Python below 3.10, you can use the pampy module to implement the switch-case statement: https://code.sololearn.com/cMn8AUh1rkb1/?ref=app
12th Jun 2021, 12:50 AM
Vitaly Sokol
Vitaly Sokol - avatar
+ 1
you can always use a dictionary. ... def func_a(): ... ... def func_z(): #random_nothing_functions switch = {<a number or string>: func_a, <a num or string>: func_b # and so on... } choice = input(<prompt>) switch[choice]()
11th Jun 2021, 5:44 PM
Slick
Slick - avatar
+ 1
the short answer is: by design choice... here's an informative discuss at stackoverflow about "why", and updated with the new python 3.10 feature wich is close to switch case: https://stackoverflow.com/questions/46701063/why-doesnt-python-have-switch-case
11th Jun 2021, 7:42 PM
visph
visph - avatar
0
Now we can switch case in python with different name which match case update you python
12th Jun 2021, 5:10 PM
Swamy
Swamy - avatar