Why python doesn't have switch cases !?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why python doesn't have switch cases !?!

There are other programming language which contains switch but why it's not available in python!?!

25th Jul 2020, 6:11 AM
Ankith M Kashyap
Ankith M Kashyap - avatar
4 Answers
+ 1
Ankith M Kashyap It's not written that way, so it's not included in the language's syntax. Look at it this way: each programming language has something the other ones doesn't have. This is the beauty of it 😃😃
25th Jul 2020, 7:05 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 1
In Python the if/elif/else statement, use of dictionary dispatch, custom functions, etc. performs the same as switch/case. The Python community has also rejected the implementation of switch/case every time the idea is mentioned... "A quick poll during my keynote presentation at PyCon 2007 shows this proposal has no popular support. I therefore reject it." https://www.python.org/dev/peps/pep-3103/#if-elif-chain-vs-dict-based-dispatch
25th Jul 2020, 3:03 PM
Steven M
Steven M - avatar
+ 1
Thanks sir Steven M
25th Jul 2020, 4:05 PM
Ankith M Kashyap
Ankith M Kashyap - avatar
0
And I have also read some posts which tells us to create our own snippets for making use of switch like function in python?! But it doesn't tell about why it doesn't have a switch case !?!
25th Jul 2020, 6:12 AM
Ankith M Kashyap
Ankith M Kashyap - avatar