First, the definition
Lambda arg1,arg2 ...: returnvalue
Ii. Examples
# !/usr/bin/python def f (x, y ): return x*yprint f (2,3)#6Lambda x,y:x*yprint g (2,3)#6
Third, switch of a realization scheme
#!/usr/bin/python from __future__ ImportDivision#A=int (raw_input (' Please input NUM1: '))#B=int (raw_input ("Please input num2:"))defJia (x, y):returnx+ydefJian (x, y):returnX-ydefCheng (x, y):returnx*ydefChu (x, y):returnx/ydefoperator (x,o,y):ifo = ='+': PrintJia (x, y)elifo = ='-': PrintJian (x, y)elifo = ='*': PrintCheng (x, y)elifo = ='/': PrintChu (x, y)Else: PassOperatord= {'+': Jia,'-': Jian,'*': Cheng,'/': Chu}defSwitchoperator (x,o,y):PrintOperatord.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)
Python Learning note four: lambda expressions and switch