【问题标题】:How are Python2's built-in reduce and functools.reduce different?Python2 内置的 reduce 和 functools.reduce 有何不同?
【发布时间】:2016-05-01 21:13:12
【问题描述】:

两者都有完全相同的文档,在我看来两者都源于https://hg.python.org/cpython/file/Modules/_functoolsmodule.c中的相同源代码。

但是,我不确定。我在 CPython 的源代码中没有找到任何其他参考。有人可以在这里解释一下吗?

【问题讨论】:

  • 一方面,Python 3 似乎放弃了对 reduce() 的支持而不使用 functools
  • >>> import functools; functools.reduce 输出<built-in function reduce>

标签: python python-2.x functools


【解决方案1】:

the documentation of functools.reduce in Python 2:

这与reduce() 的功能相同。在这个可以使用 模块以允许编写与 Python 3 更向前兼容的代码。

【讨论】:

    猜你喜欢
    • 2012-10-09
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2018-08-15
    • 1970-01-01
    • 2012-12-17
    相关资源
    最近更新 更多