python 的 reduce() 函数

reduce(func, seq) 函数对序列中的元素进行递归运算。在 3.x 的 python  中 需要从 functools 模块中导入。

求 1~100 的和

 

 用 for 循环实现上面的求和过程,代码如下:

s = 0
for i in range(1, 101):
    s += i

s

 

原文地址:https://www.cnblogs.com/shanger/p/12925321.html