Python switch case实现操作是怎样的,pythonswitch,Python里怎么实现s
Python switch case实现操作是怎样的,pythonswitch,Python里怎么实现s
Python里怎么实现switch case?
Python 里没有 Switch 语法,按官方的说法是用 if...elif... 来替代 switch...case
但是可以用 Dictionary 来实现:
def f(x): return { 'a': 1, 'b': 2, }[x]
参考:http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python
用if或者 字典 实现应该都没有问题吧。
http://stackoverflow.com/questions/11479816/what-is-the-python-equivalent-for-a-case-switch-statement
python没有switch case。switch case从逻辑上来说像是一个hash表。你可以使用python的字典来实现类似功能。
switch_dict = { "case_foo": foo(), "case_bar": bar(), ...}switch_dict.get("case", "default_case")()
楼主可以参考一下这个
http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python
编橙之家文章,
相关内容
- Python模拟登录cookie有验证码要怎么做才能抓到内容,
- python html兼容空格问题,pythonhtml兼容空格,文本框里输入
- Python django监测用户跳转页面状态求思路,pythondjango,d
- 求python访问网页并提交请求的操作思路,python思路,我要
- 求助python django-pagination分页url显示方式问题,,django-p
- 新手求Python高手看源码错误,python源码,num=10;print
- python requests库登录网站失败求分析脚本,pythonrequests,想
- 基于windows系统安装python jinja2怎么操作,pythonjinja2,我照
- Mac系统用Python连接远程mysql数据库前,需要在本机安装
- Python语言能写出类似javascript闭包吗?,pythonjavascript,va
评论关闭