python 中switch的实现
来源:互联网 发布:湛洪果 知乎 编辑:程序博客网 时间:2024/06/13 01:21
转载自:http://blog.chinaunix.net/uid-1706385-id-2834875.html
There is currently no switch statement in Python. Often this is not a problem and can be handled through a series of if-elif-else statements. However, there are many other ways to handle the deficiency. The following example shows how to create a simple switch statement in Python:
def a(s):
print s
def switch(ch):
try:
{'1': lambda : a("one"),
'2': lambda : a("two"),
'3': lambda : a("three"),
'a': lambda : a("Letter a")
}[ch]()
except KeyError:
a("Key not Found")
eg:
>>switch('1')
one
>>switch('a')
Letter a
>>switch('b')
Key not Found
0 0
- python 中switch的实现
- python中实现switch
- python中 switch 语句的实现
- Python中switch结构的实现
- python switch的实现
- Python的switch实现
- python的switch实现
- Python中switch-case实现
- Python中实现switch功能
- python switch结构的实现
- python中switch的用法
- Python中Switch Case语法实现
- Python中switch-case实现(转)
- Python实现类似switch的分支结构
- python switch语句的多种实现方法
- python实现简单的switch功能
- python switch 实现
- python实现switch功能
- 序列式容器——vector,deque,list
- 【汇编语言/底层开发】10、CALL和RET指令
- POJ 2096 Collecting Bugs (概率DP)
- HTTP状态码大全
- 用微笑面对一切令你烦恼的人或事,不久之后,你会发现令你微笑的人或事变得越来越多了。
- python 中switch的实现
- coding上传项目的基本步骤
- 第一篇
- csdn博客开通前言
- Test
- 在linux中添加ftp用户,并设置相应的权限
- godot中的场景实例化下
- ardrone_autonomy及tum_ardrone的安装
- Selenium2.0之WebDriver学习总结(1)