0

Why does python not have "switch" statement

We all are know that switch statement is best alternative of "elif" statement

20th Feb 2019, 11:27 PM
Rohit Kumar
Rohit Kumar - avatar
2 Answers
21st Feb 2019, 12:11 AM
HonFu
HonFu - avatar
+ 4
Python doesn't have a switch statement simply because it would have been difficult to implement it into the language provided the syntax used and how Python would need to run something like it. With the language, there is no way to assign a constant variable, so the developers found it difficult to implement it. Also, either way it merely does the same as an if/elif/else chain so there really would be no need to add something unnecessary that can be easily worked around (I personally like the if/elif/else chain better because the syntax makes be better satisfied that my code will do what I want it too). These posts can also help a little: https://stackoverflow.com/questions/46701063/why-doesnt-python-have-switch-case https://www.sololearn.com/Discuss/48633/?ref=app
20th Feb 2019, 11:41 PM
Faisal
Faisal - avatar