📅  最后修改于: 2020-10-30 05:25:28             🧑  作者: Mango
Python help()函数用于获取与调用期间传递的对象相关的帮助。它带有一个可选参数,并返回帮助信息。如果未提供任何参数,则显示Python帮助控制台。它在内部调用python的help函数。
help(object)
对象:可以是我们希望获得帮助的任何对象。
它返回对象的信息。
让我们来看一些help()函数的示例,以了解其功能。
# Python help() function example
# Calling function
info = help() # No argument
# Displaying result
print(info)
输出:
Welcome to Python 3.5's help utility!
# Python help() function example
# Calling function
info = help(1) # integer value
# Displaying result
print(info)
输出:
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() function example
# Calling function
info = help(list) # integer value
# Displaying result
print(info)
输出:
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].
如果没有帮助或信息,它将向控制台显示一条消息并返回None。
# Python help() function example
# Calling function
info = help("Javatpoint") # integer value
# Displaying result
print(info)
输出:
No Python documentation found for 'Javatpoint'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.
None