0
I'm wondering why python does not supporting Switch case?
5 Réponses
+ 9
It does now. But with a different name, match-case.
https://www.python.org/dev/peps/pep-0622/
+ 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
+ 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]()
+ 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
0
Now we can switch case in python with different name which match case update you python