Python#1.12.2
# # 匿名函数:简化函数定义 # # 格式:lambda 参数1,参数2...:运算 # # def func(): # print('aaa') # # # def add(a, b): # s = a + b # return s # s = lambda a, b: a + b # print(s) # s就是函数function # # result = s(1, 2) # print(result) # s1 = lambda x, y: x * y # result = s1(2, 5) # print(result) # # # # 匿名函数作为参数 # def func(x, y, func): # print(x, y) # print(func) # s = func(x, y) # print(s) # # # # 调用func # func(1, 2, lambda a, b: a + b) list1 = [3, 5, 8, 9, 0] m = max(list1) print('列表的最大值:', m) list2 = [{'a': 10, 'b': 20}, {'a': 13, 'b': 20}, {'a': 9, 'b': 20}, {'a': 29, 'b': 20}] m = max(list2, key=lambda x: x['a'])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)