python文档怎么看

2025-12-02 0 56,428

查看文档是一个程序员的基本功,这里简单介绍几种查看Python文档的方法,下面以struct模块为例。

help

在交互模式下,help函数是获取文档的好帮手,使用非常简单。

>>> import struct
>>> help(struct)
Help on module struct:
 
NAME
    struct
 
DESCRIPTION
    Functions to convert between Python values and C structs.
    Python bytes objects are used to hold the data representing the C struct
    and also as format strings (explained below) to describe the layout of data
    in the C struct.
 
    The optional first format char indicates byte order, size and alignment:
      @: native order, size & alignment (default)
      =: native order, std. size & alignment
      <: little-endian, std. size & alignment
      >: big-endian, std. size & alignment
      !: same as >
 
    The remaining chars indicate types of args and must match exactly;
    these can be preceded by a decimal repeat count:
      x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;
      ?: _Bool (requires C99; if not available, char is used instead)
      h:short; H:unsigned short; i:int; I:unsigned int;

__doc__

__doc__是每个对象都有的属性,其存放了对象文档。

>>> import struct
>>> struct.__doc__
"Functions to convert between Python values and C structs.nPython bytes objects are used to hold the data representing the C structnand also as format string
s (explained below) to describe the layout of datanin the C struct.nnThe optional first format char indicates byte order, size and alignment:n  @: native o
rder, size & alignment (default)n  =: native order, std. size & alignmentn  <: little-endian, std. size & alignmentn  >: big-endian, std. size & alignmentn
  !: same as >nnThe remaining chars indicate types of args and must match exactly;nthese can be preceded by a decimal repeat count:n  x: pad byte (no data)
; c:char; b:signed byte; B:unsigned byte;n  ?: _Bool (requires C99; if not available, char is used instead)n  h:short; H:unsigned short; i:int; I:unsigned in
t;n  l:long; L:unsigned long;

离线文档

安装Python时会自带一个chm格式的离线文档Python documention,该文档的信息比较全。

离线模块文档

Python针对模块还有一个单独的文档,该文档在浏览器中查看。

在线文档

在浏览器打开https://docs.python.org/3.4/

收藏 (0) 打赏

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

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

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

ZhiUp资源网 常见问题 python文档怎么看 https://www.zhiup.top/8999.html

相关