Python模拟switch
来源:互联网 发布:淘宝商城口红 编辑:程序博客网 时间:2024/06/07 02:48
Python模拟switch
python中是不没有switch函数的,通常的做法就是使用一个字典进行模拟。
#定义函数def zero(n): print n print "You typed zero.\n"def sqr(n): print n print "n is a perfect square\n"def even(n): print n print "n is an even number\n"def prime(n): print n print "n is a prime number\n"#定义转换的mapoptions = {0 : zero, 1 : sqr, 4 : sqr, 9 : sqr, 2 : even, 3 : prime, 5 : prime, 7 : prime,}
调用方式
options[num](n)
使用这种方式有一个缺点,参数如果不统一,怎么办呢?
0 0
- Python模拟switch
- python中模拟switch
- python switch
- python switch
- perl5:模拟SWITCH语句[转]
- python switch的实现
- python中实现switch
- python字典 switch语句
- python switch函数
- Python的switch实现
- python的switch实现
- python switch 实现
- python实现switch功能
- Python的Switch语句
- Python的switch方法
- python 实现switch
- 【模拟自动售货机】switch训练
- lua中利用table表模拟switch
- 【python】os文件操作模块
- java编程面试题
- poj_3436
- 监听APP是否切换到了后台
- User Defined Runtime Attributes
- Python模拟switch
- birt初学中遇到为问题
- linux 配置如何识别U盘
- 实现数的反转
- 记录一下seekbar遇到的问题
- KM算法 详解+模板
- Ubuntu 14.04 64bit上使用IPython玩转Docker
- Android Shape Drawable 说明
- OC之NSString简介