from functools import reduce标签:functools,reduce,编辑,add,import,随时,lambda,随记 From: https://www.cnblogs.com/lulu66/p/16663281.html
def add(x, y) : # 两数相加
return x + y
sum1 = reduce(add, [1,2,3,4,5]) # 计算列表和:1+2+3+4+5
print(sum1)
from functools import reduce
sum2 = reduce(lambda x, y: x+y, [1,2,3,4,5]) # 使用 lambda 匿名函数
print(sum2)