+ 2

Pythin Switch Case

How would i do switch case in Python? I know its not an actual thing but how would you do it in the Python way? Can you give me an example too?

10th Feb 2019, 9:47 PM
Jacob Moriarty
Jacob Moriarty - avatar
3 odpowiedzi
+ 7
or just use if and elif.
10th Feb 2019, 11:26 PM
Hubert Dudek
Hubert Dudek - avatar
0
You can store function names as values in a dictionary and treat the keys as your cases.
10th Feb 2019, 10:28 PM
HonFu
HonFu - avatar
0
Jacob Moriarty , Python 3.10 has match case syntax. Sololearn uses Python 3.9.16. https://peps.python.org/pep-0636/
14th Nov 2023, 1:35 AM
Rain
Rain - avatar