查看文檔是一個(gè)程序員的基本功,這里簡單介紹幾種查看Python文檔的方法,下面以struct模塊為例。
1.help
在交互模式下,help函數(shù)是獲取文檔的好幫手,使用非常簡單。
>>>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__是每個(gè)對象都有的屬性,其存放了對象文檔。
3.離線文檔
安裝Python時(shí)會(huì)自帶一個(gè)chm格式的離線文檔Pythondocumention,該文檔的信息比較全。
4.離線模塊文檔
Python針對模塊還有一個(gè)單獨(dú)的文檔,該文檔在瀏覽器中查看。
5.在線文檔。
以上內(nèi)容為大家介紹了怎么查看python文檔,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識(shí),請關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。