1.匿名函数定义规则: lambda 形参:返回值
def fun(*args, **kwargs):
return args, kwargs
print(lambda *args, **kwargs : (args, kwargs))
from functools import reduce
print(reduce(lambda x,y : x +y , [1,2,3,4,5]))
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/ba753775e298386998b2df32f78b953d.png)
info = [
('apple3', 200, 32),
('apple4', 40, 12),
('apple1', 40, 2),
('apple2', 1000, 23),
]
from operator import itemgetter
print(sorted(info))
print(sorted(info, key=itemgetter(1)))
print(sorted(info, key=itemgetter(2)))
print(sorted(info, key=itemgetter(1,2)))
print(sorted(info, key=itemgetter(1,2)))
add = lambda x,y : x +y
print(add(1,2))
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/21ef52545951581e537d86d22529f3cb.png)