Python 使用 reduce 函数计算列表元素的乘积
可以使用 reduce 函数来计算列表的叠乘,代码如下:
from functools import reduce
lst = [1, 2, 3, 4, 5, 6]
result = reduce(lambda x, y: x*y, lst)
print(result)
输出结果为 720,即 1x2x3x4x5x6=720。
原文地址: https://www.cveoy.top/t/topic/ns5t 著作权归作者所有。请勿转载和采集!