Re: [問題] 怎麼用 Python 寫出 switch 的功能?

作者: mikapauli (桜花)   2017-10-19 20:18:07
使用dict的方法:
def f0():
...
def f1():
...
def f2():
...
...
switch = {'c0': 0, 'c1': 1, 'c2': 2, ...}
process = (f0, f1, f2, ...)
...
[f() for f in process[switch[case]:]]

Links booklink

Contact Us: admin [ a t ] ucptt.com