查看文檔是一個程序員的基本功,這里簡單介紹幾種查看Python文檔的方法,下面以struct模塊為例。
1.help
在交互模式下,help函數是獲取文檔的好幫手,使用非常簡單。
>>>importstruct
>>>help(struct)
Helponmodulestruct:
NAME
struct
DESCRIPTION
FunctionstoconvertbetweenPythonvaluesandCstructs.
PythonbytesobjectsareusedtoholdthedatarepresentingtheCstruct
andalsoasformatstrings(explainedbelow)todescribethelayoutofdata
intheCstruct.
Theoptionalfirstformatcharindicatesbyteorder,sizeandalignment:
@:nativeorder,size&alignment(default)
=:nativeorder,std.size&alignment
<:little-endian,std.size&alignment
>:big-endian,std.size&alignment
!:sameas>
Theremainingcharsindicatetypesofargsandmustmatchexactly;
thesecanbeprecededbyadecimalrepeatcount:
x:padbyte(nodata);c:char;b:signedbyte;B:unsignedbyte;
?:_Bool(requiresC99;ifnotavailable,charisusedinstead)
h:short;H:unsignedshort;i:int;I:unsignedint;
2.__doc__
__doc__是每個對象都有的屬性,其存放了對象文檔。
3.離線文檔
安裝Python時會自帶一個chm格式的離線文檔Pythondocumention,該文檔的信息比較全。
4.離線模塊文檔
Python針對模塊還有一個單獨的文檔,該文檔在瀏覽器中查看。
5.在線文檔。
以上內容為大家介紹了怎么查看python文檔,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。