import random
f = lambda x, y: x + y
print(f(6, 22))
def count_number(a, b, c):
return lambda x: a + b + c + x
print(count_number(1, 2, 3)(4))
# 三目运算符
is_number = lambda x: "双数" if x % 2 == 0 else "单数"
print(is_number(6))
print(is_number(5))
# 匿名lambda表达式
x = lambda: random.random()
print(x())
# 配合map使用
x = map(lambda x: x * 2, [1, 2, 3, 4, 5, 6])
print(list(x))
# 进行排序
li = [{"age": 20, "name": "def"}, {"age": 25, "name": "abc"}, {"age": 10, "name": "ghi"}]
li = sorted(li, key=lambda x: x["age"])
print(li)
原文:https://www.cnblogs.com/chron/p/14979462.html