python内置help函数的详细介绍

英文文档:

help([object])

invoke the built-in help system. (this function is intended for interactive use.) if no argument is given, the interactive help system starts on the interpreter console. if the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. if the argument is any other kind of object, a help page on the object is generated.

this function is added to the built-in namespace by the site module.

说明:

  1. 在解释器交互界面,不传参数调用函数时,将激活内置的帮助系统,并进入帮助系统。在帮助系统内部输入模块、类、函数等名称时,将显示其使用说明,输入quit退出内置帮助系统,并返回交互界面。

>>> help() #不带参数
welcome to python 3.5’s help utility!
if this is your first time using python, you should definitely check out
the tutorial on the internet at http://docs.python.org/3.5/tutorial/.
enter the name of any module, keyword, or topic to get help on writing
python programs and using python modules. to quit this help utility and
return to the interpreter, just type “quit”.
to get a list of available modules, keywords, symbols, or topics, type
“modules”, “keywords”, “symbols”, or “topics”. each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as “spam”, type “modules spam”.
#进入内置帮助系统 >>> 变成了 help>
help> str #str的帮助信息
help on class str in module builtins:
class str(object)
| str(object=”) -> str
| str(bytes_or_buffer[, encoding[, errors]]) -> str
|
| create a new string object from the given object. if encoding or
| errors is specified, then the object must expose a data buffer
| that will be decoded using the given encoding and error handler.
| otherwise, returns the result of object.__str__() (if defined)
| or repr(object).
| encoding defaults to sys.getdefaultencoding().
| errors defaults to ‘strict’.
|
| methods defined here:
|
| __add__(self, value, /)
| return self+value.
…………………………..
help> 1 #不存在的模块名、类名、函数名
no python documentation found for ‘1’.
use help() to get the interactive help utility.
use help(str) for help on the str class.
help> quit #退出内置帮助系统
you are now leaving help and returning to the python interpreter.
if you want to ask for help on a particular object directly from the
interpreter, you can type “help(object)”. executing “help(‘string’)”
has the same effect as typing a particular string at the help> prompt.
# 已退出内置帮助系统,返回交互界面 help> 变成 >>>
>>>

2. 在解释器交互界面,传入参数调用函数时,将查找参数是否是模块名、类名、函数名,如果是将显示其使用说明。

>>> help(str)
help on class str in module builtins:
class str(object)
| str(object=”) -> str
| str(bytes_or_buffer[, encoding[, errors]]) -> str
|
| create a new string object from the given object. if encoding or
| errors is specified, then the object must expose a data buffer
| that will be decoded using the given encoding and error handler.
| otherwise, returns the result of object.__str__() (if defined)
| or repr(object).
| encoding defaults to sys.getdefaultencoding().
| errors defaults to ‘strict’.
|
| methods defined here:
|
| __add__(self, value, /)
| return self+value.
|
***************************

以上就是python内置help函数的详细介绍的详细内容,更多请关注 第一php社区 其它相关文章!

Posted in 未分类

发表评论