python求积函数是什么

1178
2021/1/23 9:00:45
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python同步赋值语句怎么调用