在线文档
最简单的方法是使用 Google 获取在线文档。没有一个地方可以找到所有模块的所有文档。但是,一些常见的有:
如果您需要离线文档,还有其他几种可能:
下载它
您可以下载 HTML 或 PDF 格式的文档:https://docs.python.org/3/download.html
当您有一个网络服务器正在运行时,您可以使用 HTML 版本并像过去一样通过浏览器访问它。 HTML 站点看起来就像您习惯的那样。甚至搜索也可以离线工作,因为它是用 JavaScript 实现的。
PyDoc
像 Debian 这样的一些发行版提供了一个python-doc 包。您可以通过以下方式访问它
pydoc -p [some port number] 或通过pydoc -g。这将创建一个本地 Web 服务器。然后你就可以打开浏览器看看了:
控制台:帮助(...)
Python 交互式控制台有一个内置的help(...) 系统。您可以在没有参数的情况下调用它:
$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 2.7! This is the online 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/2.7/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, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>
或者你可以用你想知道的参数来调用它。这可以是任何东西(模块、类、函数、对象……)。它看起来像这样:
>>> a = {'b':'c'}
>>> help(a)
Help on dict object:
class dict(object)
| dict() -> new empty dictionary
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs
| dict(iterable) -> new dictionary initialized as if via:
| d = {}
| for k, v in iterable:
| d[k] = v
| dict(**kwargs) -> new dictionary initialized with the name=value pairs
| in the keyword argument list. For example: dict(one=1, two=2)
|
| Methods defined here:
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| D.__contains__(k) -> True if D has a key k, else False
|
| __delitem__(...)
| x.__delitem__(y) <==> del x[y]
|
| __eq__(...)
| x.__eq__(y) <==> x==y
|
| __ge__(...)
| x.__ge__(y) <==> x>=y
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(...)
: (scroll)