+ 1

Switch in Pyhton

Is there a switch in python?

24th Nov 2018, 10:34 AM
Marcelo Lobo
5 Réponses
+ 3
If you need switch case in python then you can use dictionary for it.i know there is no original switch case in python but mostly people also call dictionary as switch case for python. because it is similar to switch case. Check this link. https://youtu.be/gllUwQnYVww
24th Nov 2018, 4:18 PM
Maninder $ingh
Maninder $ingh - avatar
+ 3
Unfortunately not :/ I somewhere read a post on StackOverflow about the reasons and that they considered it, though it's not "pythonic" and using elif doesn't extend the code much.
24th Nov 2018, 10:40 AM
Matthias
Matthias - avatar
+ 2
Unfortunately, no. Have a look on StackOverflow, they have some ways to "simulate" a switch statement, but it's not like the switch statement used in JS or C/++.
24th Nov 2018, 11:52 AM
inxanedev!
inxanedev! - avatar
+ 1
I use a chain of if..elif..else
24th Nov 2018, 1:34 PM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar
+ 1
Thanks for the answers. Emulate Switch Case for Functions, incredible.
24th Nov 2018, 4:49 PM
Marcelo Lobo