温馨提示×

python求积函数是什么

九三
1805
2021-01-23 09:00:45
栏目: 编程语言

python求积函数是什么

python中使用reduce函数求积,具体方法如下:

reduce():reduce()函数的作用是对参数序列中元素进行累积。

reduce()函数语法:

reduce(function, iterable[, initializer])

参数:

function:函数,有两个参数。

iterable:可迭代对象。

initializer:初始参数。

reduce()函数使用方法:

from functools import reduce

def prod(x,y):

return x * y

L = reduce(prod,[3,5,7,9])

print(L)

输出结果为:

945

0