Python help() 函数

2024年9月26日 | 阅读 2 分钟

Python help() 函数用于获取与调用期间传递的对象相关的帮助。它接受一个可选参数并返回帮助信息。 如果没有给出参数,它将显示 Python 帮助控制台。 它在内部调用 python 的 help 函数。

签名

参数

对象:它可以是我们要获取帮助的任何对象。

返回

它返回对象的信息。

让我们看一些 help() 函数的例子来了解它的功能。

Python help() 函数示例 1

输出

Welcome to Python 3.5's help utility!

Python help() 函数示例 2

输出

Help on int object:

class int(object)
 |  int(x=0) -> integer
 |  int(x, base=10) -> integer
 |  
 |  Methods defined here:
 |  
 |  __abs__(self, /)
 |      abs(self)
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __and__(self, value, /)
 |      Return self&value.

Python help() 函数示例 3

如果对象是列表,它将打开列表模块及其类。 请参阅输出。

输出

Help on class list in module builtins:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items
 |  
 |  Methods defined here:
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __delitem__(self, key, /)
 |      Delete self[key].

Python help() 函数示例 4

如果没有帮助或信息,它会在控制台上显示一条消息并返回 None。

输出

No Python documentation found for 'Javatpoint'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

None

下一个主题Python 函数