美文网首页
python 第二章函数

python 第二章函数

作者: 不规则先生 | 来源:发表于2016-11-23 14:19 被阅读15次

语法

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

相关文章

网友评论

      本文标题:python 第二章函数

      本文链接:https://www.haomeiwen.com/subject/yrhvpttx.html