当前位置:主页 > 软件编程 > Python代码 >

使用Python中的reduce()函数求积的实例

时间:2021-02-12 08:51:27 | 栏目:Python代码 | 点击:

编写一个prod()函数,可以接受一个list并利用reduce()求积。

from functools import reduce
def prod(x,y):
 return x * y
L = reduce(prod,[3,5,7,9])
print(L)

打印结果如下:

您可能感兴趣的文章:

相关文章