网络编程
位置:首页>> 网络编程>> Python编程>> 使用Python中的reduce()函数求积的实例

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

作者:dou_being  发布时间:2021-08-14 04:35:47 

标签:Python,reduce,求积

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


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

打印结果如下:

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

来源:https://blog.csdn.net/dou_being/article/details/79921983

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com