打印函数来自哪个modu

2024-04-27 02:21:30 发布

您现在位置:Python中文网/ 问答频道 /正文

作为一个初学者,我理解的是Python标准库(PSL)提供了很多模块,这些模块提供了很多功能,但是如果我想使用这些模块,那么我必须导入模块,例如,sysos等。这些模块是PSL模块,但是仍然需要导入。你知道吗

现在,我想知道如果是这样的话,那么在不导入任何东西的情况下,我怎么能够使用像printlistlen等函数呢。?是不是他们的“支持是内置在翻译中的”?你知道吗


Tags: 模块函数功能标准lenossys情况
3条回答

print函数来自builtins模块。 您可以找到它的文档here。你知道吗

下面是一个示例会话。 我首先检查print来自哪个模块,它存储在__module__属性中。 然后,导入builtins模块,检查其print函数是否与前缀less print相同。你知道吗

>>> print.__module__
'builtins'
>>> import builtins
>>> builtins.print("hello")
hello
>>> print is builtins.print
True

是的。它们是内置函数(或者在list的情况下是内置类)。如果希望对名称进行限定访问,可以显式导入the ^{} module(Py2)或the ^{} module(Py3),但默认情况下,只要尝试访问全局名称时在模块全局中找不到名称,就会搜索这些模块。但根据文件,它们通常不需要:

This module is not normally accessed explicitly by most applications, but can be useful in modules that provide objects with the same name as a built-in value, but in which the built-in of that name is also needed.

您应该读取built-in函数的页面

引用:

The Python interpreter has a number of functions and types built into it that are always available.

相关问题 更多 >