首页 > 其他分享 >随记-随时编辑

随记-随时编辑

时间:2022-09-06 21:00:54浏览次数:59  
标签:functools reduce 编辑 add import 随时 lambda 随记

from functools import reduce
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)

标签:functools,reduce,编辑,add,import,随时,lambda,随记
From: https://www.cnblogs.com/lulu66/p/16663281.html

相关文章