The World Wide Web, restored to 800 pixels of glory.
GeezerVison is showing www.runoob.com — Python3 reduce() 函数
不梦君
在 Python3 中,reduce() 函数已经被从全局名字空间里移除了,它现在被放置在 functools 模块里,如果想要使用它,则需要通过引入 functools 模块来调用 reduce() 函数:
from functools import reduce
实例:
from functools import reduce def add(x,y): return x + y print (reduce(add, range(1, 101)))
输出结果为:
5050