Heim  >  Artikel  >  Backend-Entwicklung  >  Detaillierte Einführung in die integrierte Hilfefunktion von Python

Detaillierte Einführung in die integrierte Hilfefunktion von Python

高洛峰
高洛峰Original
2017-03-21 10:49:192291Durchsuche

Englische Dokumentation:

help([Objekt])

Rufen Sie das integrierte Hilfesystem auf. (Diese Funktion ist für die interaktive Verwendung gedacht.) Wenn kein Argument angegeben ist, wird das interaktive Hilfesystem auf der Dolmetscherkonsole gestartet eine Zeichenfolge, dann wird die Zeichenfolge als Name eines Moduls, einer Funktion, einer Klasse, einer Methode, eines Schlüsselworts oder eines Dokumentationsthemas gesucht und eine Hilfeseite wird auf der Konsole gedruckt. Wenn es sich bei dem Argument um ein anderes Objekt handelt, wird eine Hilfe angezeigt Seite auf dem Objekt wird generiert.

Diese Funktion wird dem integrierten Namespace durch das Modul site hinzugefügt.

Beschreibung:

1. Wenn in der interaktiven Schnittstelle des Interpreters eine Funktion ohne Übergabe von Parametern aufgerufen wird, wird das integrierte Hilfesystem aktiviert und das Hilfesystem wird eingegeben. Wenn Sie den Namen eines Moduls, einer Klasse, einer Funktion usw. in das Hilfesystem eingeben, werden dessen Verwendungsanweisungen angezeigt. Geben Sie „Quit“ ein, um das integrierte Hilfesystem zu verlassen und zur interaktiven Oberfläche zurückzukehren.

>>> 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. Bei der Übergabe von Parametern zum Aufrufen einer Funktion wird geprüft, ob es sich bei den Parametern um Modulnamen, Klassennamen und Funktionsnamen handelt Gebrauchsanweisungen werden angezeigt.

>>> 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.
 |  
  ***************************

Das obige ist der detaillierte Inhalt vonDetaillierte Einführung in die integrierte Hilfefunktion von Python. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn