标签:pytho cas style from values stat ict rom str
摘自网络
python本身没有switch语句,解决方法有以下3种:
#coding: utf-8
from __future__ import division
def jia(x,y):
print x+y
def jian(x,y):
print x-y
def cheng(x,y):
print x*y
def chu(x,y):
print x/y
operator = {‘+‘:jia,‘-‘:jian,‘*‘:cheng,‘/‘:chu}
def f(x,o,y):
operator.get(o)(x,y)
f(3,‘+‘,2)
result = {
‘a‘: lambda x: x * 5,
‘b‘: lambda x: x + 7,
‘c‘: lambda x: x - 2
}[value](x)
标签:pytho cas style from values stat ict rom str
原文地址:http://www.cnblogs.com/ph829/p/7040355.html