lambda()是python对函数的一种简单表达
当一个函数只用一次,又比较简单,没有必要另外定义的时候,可以用lambda(),使得程序更简洁.
for example:
1、
def square():
return x**2
map(square, [1, 2, 3, 4, 5])
2、
map(lambda x : x**2, [1, 2, 3, 4,5])
lambda()是python对函数的一种简单表达
当一个函数只用一次,又比较简单,没有必要另外定义的时候,可以用lambda(),使得程序更简洁.
for example:
1、
def square():
return x**2
map(square, [1, 2, 3, 4, 5])
2、
map(lambda x : x**2, [1, 2, 3, 4,5])