python switch函数
来源:互联网 发布:美工岗位职责是那些 编辑:程序博客网 时间:2024/06/05 14:57
python并没有提供switch语句!python可以通过字典实现switch语句的功能。
1)首先,定义一个字典;2)其次,调用字典的get()获取相应的表达式。
#!/usr/bin/python#coding:utf8from __future__ import division#使除非操作自动识别小数结果def jia(x,y):return x+ydef jian(x,y):return x-ydef cheng(x,y):return x*ydef chu(x,y):return x/yoperator = {"+":jia,"-":jian,"*":cheng,"/":chu} print operator["/"](3,2)def f(x,o,y):print operator.get(o)(x,y)#类似switch函数操作f(3,"/",2)#函数调用
- python switch函数
- python switch
- python switch
- Python 视频学习 21-24 switch 内建函数
- 使用Python函数和字典实现Java中的switch功能
- python之 利用字典与函数实现switch case功能
- python switch的实现
- python中实现switch
- python字典 switch语句
- Python的switch实现
- Python模拟switch
- python的switch实现
- python switch 实现
- python实现switch功能
- Python的Switch语句
- Python的switch方法
- python中模拟switch
- python 实现switch
- ios应用程序生命周期
- python lambda函数
- POJ 3667
- 真正的冒泡排序
- pthread_getspecific()和pthread_setspecific()的使用方法
- python switch函数
- 在github上部署第二个repository
- Unix编程艺术——Unix哲学
- 读一本跟技术无关的书籍
- 调用支付宝 报Undefined symbols for architecture armv7 _CreateRSADataVerifier的错误
- 笑话
- python 内建函数
- SSH 配置文件管理
- Android学习.0(Android项目目录结构)