pHo*_*pec 0 python switch-statement
Python是否实现switch/case或者python开发人员是否想要使用一系列if, elif, else语句?
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)
| 归档时间: |
|
| 查看次数: |
681 次 |
| 最近记录: |