语法
lambda函数的语法仅包含单个语句,如下:
lambda [arg1 [,arg2,.....argn]]:expression
以下为例子来说明函数lambda形式是如何工作的:
#!/usr/bin/python
# Function definition is here
sum = lambda arg1, arg2: arg1 + arg2;
# Now you can call sum as a function
print "Value of total : ", sum( 10, 20 )
print "Value of total : ", sum( 20, 20 )
当执行上面的代码,产生以下结果:
Value of total : 30
Value of total : 40