如何查看python文档

2025-12-01 0 15,252

调用help函数,可以看到一个函数或者方法的字符串文档。

In [1]: import requests
In [2]: help(requests.get)
Help on function get in module requests.api:
get(url, params=None, **kwargs)
    Sends a GET request.
    :param url: URL for the new :class:`Request` object.
    :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`
    Request`.
    :param **kwargs: Optional arguments that ``request`` takes.
    :return: :class:`Response ` object
    :rtype: requests.Response

相关推荐:《Python入门教程》

使用dir可以查看模块或对象都有哪些方法。

In [3]: dir(requests)
Out[3]:
['ConnectionError',
 'HTTPError',
 'compat',
 'cookies',
 'delete',
 'exceptions',
 'get',
 'head',
 'hooks',
  ...

使用ipython+?查看

In [4]: requests.get?
Type:        function
String form: 
File:        /Library/Python/2.7/site-packages/requests/api.py
Definition:  requests.get(url, params=None, **kwargs)
Docstring:
Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
:param **kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response ` object
:rtype: requests.Response

使用pydoc查看字符串文档

python -m pydoc requests
Help on package requests:
NAME
    requests
FILE
    /Library/Python/2.7/site-packages/requests/__init__.py
DESCRIPTION
    requests HTTP library   
    Requests is an HTTP library, written in Python, for human beings. Basic GET
    usage:
       >>> import requests
       >>> r = requests.get('https://www.python.org')
       >>> r.status_code
       200
       >>> 'Python is a programming language' in r.content
       True

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 如何查看python文档 https://www.zhiup.top/5188.html

相关