Python学习文档指引

时间:2022-07-18 19:31:03

Python文档资源:

形式 角色
#注释 文件中的文档
dir函数 对象中可用属性的列表
文档字符串:__doc__ 附加在对象上的文件中的文档
PyDoc:help函数 对象的交互帮助
PyDoc:HTML报表 浏览器中的模块文档
标准手册 正式的语言和库的说明
网站资源 在线教程、例子等
出版的图书 商业参考书籍

1、#注释

#注释只能从源代码文件中看到,若要查看#注释信息,只需要获取相应的模块文件即可。

2、Dir函数

获取对象内可用所有属性列表的简单方式(如,对象的方法以及简单的数据项),它能够调用任何有属性的对象。

Python学习文档指引

Python学习文档指引

3、文档字符串:_ _doc_ _(自动附加在对象上的文档)
这类注释是写成字符串,放在模块文件、函数以及类语句的顶端,在任何可执行程序代码前。Python会自动封装这个字符串,使其成为相应对象的__doc__属性。
调用模块中类的方法函数的文档字符串,可以通过路径访问类:module.class.method.__doc__
"""
Module documentation
Words Go Here
""" spam=40 def square(x):
"""
function documentation
can we have your liver then?
"""
return x **2 class employee:
"class documentation"
pass print(square(4))
print(square.__doc__)
>>> import docstrings
16 function documentation
can we have your liver then? >>> print(docstrings.__doc__) Module documentation
Words Go Here >>> print(docstrings.square.__doc__) function documentation
can we have your liver then? >>> print(docstrings.employee.__doc__)
class documentation
内置文档字符串
 
Python学习文档指引
 
Python学习文档指引
4、PyDoc:help函数
主要PyDoc接口:内置help函数和PyDoc GUI/HTML接口。可对模块、内置函数、方法以及类型使用help。
Python学习文档指引
 
Python学习文档指引
 
5、PyDoc:HTML报表
Python学习文档指引
 
6、Python Manual
Python学习文档指引