28.4. future_builtins — Python 3 内置程序

2.6 版的新Function。

该模块提供了 2.x 中存在的Function,但在 Python 3 中具有不同的行为,因此无法将其放入 2.x 内置名称空间中。

相反,如果要编写与 Python 3 内置程序兼容的代码,请从此模块导入它们,如下所示:

from future_builtins import map, filter

... code using Python 3-style map and filter ...

将 python 2 代码移植到 python 3 的2to3工具将识别这种用法,而不再使用新的内置函数。

Note

Python 3 print()函数已经在内置函数中,但是除非您使用适当的 future 语句,否则无法从 Python 2 代码访问该函数:

from __future__ import print_function

可用的内置函数包括:

Note

在 Python 3 中,map()不接受None作为函数参数。

首页