其他语言中多重选择方式一般为switch(a)
{
case1;
case2;
case3;
}
而python中没有switch case语句,一般使用的是if else if ......或者
def numbers_to_strings(argument):
switcher = {
0: "zero",
1: "one",
2: "two",
}
return switcher.get(argument, "nothing")
这段代码类似于
function(argument){
switch(argument) {
case 0:
return "zero";
case 1:
return "one";
case 2:
return "two";
default:
return "nothing";
};
};