好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python中reduce()函数的示例

reduce() 函数会对参数序列中元素进行累积,下面这篇文章主要给大家介绍了关于python中reduce()函数的使用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧。

#python 3. 6 
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579 
# 
from functools import reduce 
 
result = reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) 
print(result) 
#python 3. 6 
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579 
# 
from functools import reduce 
 
n = 3 
print(reduce(lambda x, y: x * y, range(1, n + 1))) # 6 

总结

以上就是python中reduce()函数的示例的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python中reduce()函数的示例的详细内容...

  阅读:37次