3 Antworten
+ 7
In my opinion python doesnt need switch statements because it got something much better : a "Mapping table"
so instead of the old:
switch(val){
case 1: do1()
break;
case 2: do2()
break;
default: do3()
}
you can use the much better table:
x = the value you want to use
mydefault = 3
{
1 : do1,
2: do2,
3: do3,
}.get(x,mydefault)()
+ 3
if and Elifs are so short that there is no need for switch in python like other languages
+ 2
I don't see the need for a switch.
The switch can essentially done with if-elif-else statements (and while loop if needed)