Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里

reduce函数:
在Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里 用的话要 先引入:
>>> from functools import reduce 
>>> print(l1)
[0, 1, 2, 3, 4, 5, 6]
>>> reduce( f4, l1 )
21

from functools import reduce

def add(x,y):
    return x + y

print (reduce(add, range(1, 101)))

输出结果为:

5050
原文地址:https://www.cnblogs.com/timssd/p/4765362.html