#匿名函数lambda 匿名函数:lambda是一种快速定义单行的最小函数, lambda x,y,z: xyz 匿名函数返回的是一个对象
In [8]: def fun(x, y):
...: return x*y
In [9]: fun(2, 3)
Out[9]: 6
# 两个解雇噢是等价的
In [10]: r = lambda x,y: x*y
In [11]: r(2, 3)
Out[11]: 6
#函数reduce
-
语法 reduce(function, sequence[, initial]) -> value
-
实例 eg: reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5)
In [7]: reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
Out[7]: 15