为什么在 Python 中的 help('modules'') 中使用引号
Why use quotes in help('modules'') in Python
在试用 Python 交互式帮助时,我注意到在尝试查看 python 解释器中所有可用模块的列表时,我们需要在 "modules" 周围使用引号。
Microsoft Windows [Version 10.0.17763.195]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\amber>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help('modules')
但是,我们在尝试阅读对象的帮助时不需要使用引号;例如-
>>> help(tuple)
为什么会有这种差异?
我试图通过重复 Google 搜索以及搜索 Stack Overflow 找到答案,但最接近的问题是关于 returning some errors or not addressing the quote, while question in other websites 没有任何答案。
modules
不是 Python 中的内置 class,而元组是。事实上,您可以在使用 help
时将引号括起来。这是完全有效的:
help("tuple")
但是,我们不需要这样做的原因是,通过执行 help(tuple)
,我们将 class 传递给 help
,所以 help
要做的就是向我们提供有关 class.
的信息
请注意,如果您键入 help(modules)
,您将看到未定义模块 - 它不是内置的 class。
"If string is passed as an argument, name of a module, function, class, method, keyword, or documentation topic, and a help page is printed."
参见:link
在试用 Python 交互式帮助时,我注意到在尝试查看 python 解释器中所有可用模块的列表时,我们需要在 "modules" 周围使用引号。
Microsoft Windows [Version 10.0.17763.195]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\amber>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help('modules')
但是,我们在尝试阅读对象的帮助时不需要使用引号;例如-
>>> help(tuple)
为什么会有这种差异?
我试图通过重复 Google 搜索以及搜索 Stack Overflow 找到答案,但最接近的问题是关于 returning some errors or not addressing the quote, while question in other websites 没有任何答案。
modules
不是 Python 中的内置 class,而元组是。事实上,您可以在使用 help
时将引号括起来。这是完全有效的:
help("tuple")
但是,我们不需要这样做的原因是,通过执行 help(tuple)
,我们将 class 传递给 help
,所以 help
要做的就是向我们提供有关 class.
请注意,如果您键入 help(modules)
,您将看到未定义模块 - 它不是内置的 class。
"If string is passed as an argument, name of a module, function, class, method, keyword, or documentation topic, and a help page is printed." 参见:link