美文网首页
python 模块 - functools

python 模块 - functools

作者: tafanfly | 来源:发表于2019-06-03 17:03 被阅读0次

functools 模块应用于高阶函数,即参数或(和)返回值为其他函数的函数。通常来说,此模块的功能适用于所有可调用对象。

functools.reduce

reduce把函数作用在一个序列上,且函数接收两个参数,reduce把N-2和N-1的计算结果继续和序列的下一个元素N做累积计算。

from functools import reduce

s = reduce(lambda x, y: x+y, [1, 2, 3, 4]) #相当于(((1+2)+3)+4)

print (s)
10

待续~~

相关文章

网友评论

      本文标题:python 模块 - functools

      本文链接:https://www.haomeiwen.com/subject/kgzcxctx.html