Python使用Switch Case?

pHo*_*pec 0 python switch-statement

Python是否实现switch/case或者python开发人员是否想要使用一系列if, elif, else语句?

Bha*_*rel 5

Python没有实现switch.另一种方法是使用像这样的字典:

def func1():
    pass

def func2():
    pass

switch = {
    "do1": func1,
    "do2": func2,
}

do_str = "do1"
switch[do_str]()
Run Code Online (Sandbox Code Playgroud)