为什么python中没有switch case语句
终于知道了python中映射的设计哲学.
我自己写的code :
class order_status_switcher(object):
def get_order_status(self,argument= checkUserAppBookDateResult(appkey,"",1,token)):
#dispatch method
method_name = 'number_'+str(argument.get("data").get("orderResultModel").get("orderStatus"))
# Get the method from 'self'. Default to a lambda.
method = getattr(self,method_name,lambda :"nothing")
# Call the method as we return it
return method()
# get orderStatus=1,orderStatusDesc="已受理"
def number_1(self):
return "已受理"
#get orderStatus=2,orderStatusDesc="已接单"
def number_2(self):
return "已接单"
#get orderStatus=3,orderStatusDesc="已出发"
def number_3(self):
return "已出发"
#get orderStatus=4,orderStatusDesc="服务中"
def number_4(self):
return "服务中"
看完这段代码你就理解了吧.
原文地址:
https://www.pydanny.com/why-doesnt-python-have-switch-case.html
翻译:
http://python.jobbole.com/82008/
为什么python中没有switch case语句的更多相关文章
- java中的Switch case语句
java中的Switch case 语句 在Switch语句中有4个关键字:switch,case break,default. 在switch(变量),变量只能是整型或者字符型,程序先读出这个变量的 ...
- Python | 基础系列 · Python为什么没有switch/case语句?
与我之前使用的所有语言都不同,Python没有switch/case语句.为了达到这种分支语句的效果,一般方法是使用字典映射: def numbers_to_strings(argument): sw ...
- Java中的Switch....case语句:
一.格式: switch(表达式){ case 常量表达式1: 语句1; case 常量表达式2: 语句2; … case 常量表达式n: 语句n; default: ...
- C#中,switch case语句中多个值匹配一个代码块的写法
switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...
- python技巧 switch case语句
不同于C语言和SHELL,python中没有switch case语句,关于为什么没有,官方的解释是这样的 使用Python模拟实现的方法: def switch_if(fun, x, y): ...
- python 中的"switch"用法
转载:http://python.jobbole.com/82008/ 为什么Python中没有Switch/Case语句? 不同于我用过的其它编程语言,Python 没有 switch / case ...
- 逆向知识第九讲,switch case语句在汇编中表达的方式
一丶Switch Case语句在汇编中的第一种表达方式 (引导性跳转表) 第一种表达方式生成条件: case 个数偏少,那么汇编中将会生成引导性的跳转表,会做出 if else的情况(类似,但还是能分 ...
- 为什么说在使用多条件判断时switch case语句比if语句效率高?
在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...
- switch… case 语句的用法
switch… case 语句的用法 public class Test7 { public static void main(String[] args) { int i=5; switch(i ...
随机推荐
- Apigee 简介与简单试用
 Apigee (国内访问需要***)是一家成立于2004年的API管理公司,于2016年9月被Google收购,作为Google云的服务之一.Apigee提供从API设计.开发.管理.门户.网关等 ...
- Python的浮点数损失精度问题
本篇讨论的现象可以从下面这段脚本体现出来: >>> x = 0.0 >>> for i in range(10): x += 0.1 print(x) 0.1 0. ...
- Asp.Net WebApi接口返回值IHttpActionResult
WebApi是微软在VS2012 MVC4版本中绑定发行的,webapi2.0同mvc5发行的 webapi一共有以下接口返回值 1.void无返回值2.IHttpActionResult Json( ...
- 转载:Quartz.NET 入门
分享自:http://www.cnblogs.com/jys509/p/4628926.html 概述 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮 ...
- shell脚本自动登录服务器
#!/bin/sh function trapper(){ trap 'exit 1' EXIT QUIT; } serverArr=( guard-boot-001,10.1.17.12 guard ...
- 学习笔记:The Log(我所读过的最好的一篇分布式技术文章)
前言 这是一篇学习笔记. 学习的材料来自Jay Kreps的一篇讲Log的博文. 原文非常长.可是我坚持看完了,收获颇多,也深深为Jay哥的技术能力.架构能力和对于分布式系统的理解之深刻所折服.同一时 ...
- hdoj:2071
Max Num Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- RTT(往返时间)和RPC
RTT(Round-Trip Time)往返时间在计算机网络中它是一个重要的性能指标.表示从发送端发送数据开始,到发送端收到来自接收端的确认(接收端收到数据后便立即发送确认,不包含数据传输时间)总共经 ...
- SAP 生产订单变更管理 OCM Order Changement Management
SAP OCM Order Changement Management 一.目的 订单变更管理系统是当我们的订单(生产订单.计划订单.采购订单)已经存在的时候,其物料主数据或销售数据有变更时,我们可 ...
- error connecting: Timeout expired 超时时间已到. 达到了最大池大小 错误及Max Pool Size设置
[参考]Timeout expired 超时时间已到. 达到了最大池大小 错误及Max Pool Size设置 [参考][数据库-MySql] MySqlConnection error connec ...