Why Doesn't Python Have Switch/Case? Tuesday, June 09, 2015 (permalink) Unlike every other programming language I've used before, Python does not have a switch or case statement. To get around this fact, we use dictionary mapping: def numbers_to_stri…
不同于C语言和SHELL,python中没有switch case语句,关于为什么没有,官方的解释是这样的 使用Python模拟实现的方法: def switch_if(fun, x, y): if fun == 'add': return x + y elif fun == 'sub': return x - y elif fun == 'mul': return x * y elif fun == 'div': …