python文档
形式 # 角色
注释 文件中的文档
dir函数 对象中可用属性的列表
文档字符串__doc__ 附加在对象文件中的文档
标准手册 正式的语言和库的说明
网站 在线教程,例子
书籍 商业参考书籍
注释
代码编写的最基本的方式,文档字符串用于较大功能的文档
而# 用于较小功能的文档
dir函数
抓取对象内可用的所有属性列表的简单方式
import random
print(dir(random))
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST',
'SystemRandom', 'TWOPI', '_BuiltinMethodType', '_MethodType', '_Sequence',
'_Set', 'all', 'builtins', 'cached', 'doc', 'file',
'loader', 'name', 'package', 'spec', '_acos', '_bisect',
'_ceil', '_cos', '_e', '_exp', '_inst', '_itertools', '_log', '_pi', '_random',
'_sha512', '_sin', '_sqrt', '_test', '_test_generator', '_urandom', '_warn',
'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss',
'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate',
'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle',
'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']
print(dir('1') == dir(''))
True
__doc__文档字符串,这类注释是写成字符串,放在模块文件,函数以及语句的顶端
在可执行代码执行前,会自动封装这个字符串,也就是文档字符串,使他成为__doc__
属性
内置文档字符串可以用__doc_来查看
import sys
print(sys.doc)
...
print(sys.getrefcount.doc)
getrefcount(object) -> integer
Return the reference count of object. The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().
print(int.doc)
...
help函数
启动pydoc来查看文档,如help函数和PyDocGUI、HTML接口
print(help(int))
浙公网安备 33010602011771号