带参数的Python switch语句

时间:2018-10-03 16:56:02

标签: python switch-statement

我一直在阅读有关Python“ switch”语句(即here)的信息,但是还没有找到将不同的参数集传递给switch语句字典中调用的方法的方法:

options = {0 : zero,
    1 : one,
    2 : two
}
options[num]()

def zero():
    #some code goes here

当被调用的方法不接受任何参数时,这种方法很好用,但是如果方法onetwo需要不同的参数,我该怎么做?

def one(p1):
    #some code goes here

def two(p1, p2):
    #some code goes here

如果... elif ... elif ...

0 个答案:

没有答案