国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

python學(xué)習(xí)筆記四:lambda表達(dá)式和switch

2019-11-14 17:26:47
字體:
供稿:網(wǎng)友

一、定義

lambda arg1,arg2... : returnValue

二、示例

#!/usr/bin/pythondef f(x,y):    return x*yPRint f(2,3)#6g = lambda x,y:x*yprint g(2,3)#6

三、switch的一種實現(xiàn)方案

#!/usr/bin/pythonfrom __future__ import division#a=int(raw_input('please input num1:'))#b=int(raw_input("please input num2:"))def jia(x,y):    return x+ydef jian(x,y):    return x-ydef cheng(x,y):    return x*ydef chu(x,y):    return x/ydef Operator(x,o,y):    if o == '+':        print jia(x,y)    elif o == '-':        print jian(x,y)    elif o == '*':        print cheng(x,y)    elif o == '/':        print chu(x,y)    else:        passoperatord = {'+':jia,'-':jian,'*':cheng,'/':chu}def switchoperator(x,o,y):    print operatord.get(o)(x,y)operator(2,'+', 4)operator(2,'-', 4)operator(2,'*', 4)operator(2,'/', 4)switchoperator(2,'+', 4)switchoperator(2,'-', 4)switchoperator(2,'*', 4)switchoperator(2,'/', 4)

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 车险| 吴旗县| 大竹县| 东丽区| 樟树市| 武义县| 恩平市| 贺兰县| 黎川县| 连城县| 房山区| 称多县| 黑水县| 绵竹市| 祁东县| 枝江市| 黄石市| 南城县| 阜新| 通许县| 湘西| 新沂市| 弥渡县| 宁安市| 宝兴县| 辉南县| 巫溪县| 达孜县| 通山县| 峡江县| 三门峡市| 宁都县| 会昌县| 陇西县| 昌宁县| 洛隆县| 宝鸡市| 前郭尔| 林周县| 永昌县| 利辛县|