lambda:这是Python支持一种有趣的语法,它容许你快速定义单行的最小函数,相似与C语言中的宏,这些叫作lambda的函数,是从LISP借用来的,能够用在任何须要函数的地方:python
>>> test = lambda x, y: x + y >>> test(1,2) 3
filter(function, sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tuple(取决于sequence的类型)返回.函数
>>> tt = (1,2,3,4,) >>> filter(lambda x:x == 2, tt) (2,)
map(function, sequence) :对sequence中的item依次执行function(item),见执行结果组成一个List返回spa
>>> map(lambda x: x*x, range(1,4)) [1, 4, 9] >>>
reduce(function, sequence, starting_value):对sequence中的item顺序迭代调用function,若是有starting_value,还能够做为初始值调用code
>>> tt = (1,2,3,4) >>> reduce(lambda x,y: x - y, range(1,4)) -4 >>> reduce(lambda x, y: x + y, range(1,4)) 6