g = lambda x:x+1
可以看一下结果:
g(1)
>>>2
g(2)
>>3
当然,你也可以这样使用:
lambda x:x+1(1)
>>>2
以下是几个函数实例
>>> foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
>>>
>>> print filter(lambda x: x % 3 == 0, foo)
[18, 9, 24, 12, 27]
>>>
>>> print map(lambda x: x * 2 + 10, foo)
[14, 46, 28, 54, 44, 58, 26, 34, 64]
>>>
>>> print reduce(lambda x, y: x + y, foo)
139