溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

查看python模塊的方法

發(fā)布時(shí)間:2020-08-13 14:49:03 來(lái)源:億速云 閱讀:180 作者:小新 欄目:編程語(yǔ)言

小編給大家分享一下查看python模塊的方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

python的一個(gè)優(yōu)勢(shì)是有著大量自帶和在線的模塊(module)資源,可以提供豐富的功能,在使用這些模塊的時(shí)候,如果每次都去網(wǎng)站找在線文檔會(huì)過(guò)于耗費(fèi)時(shí)間,結(jié)果也不一定準(zhǔn)確。因此這里介紹下python自帶的查看幫助功能,可以在編程時(shí)不中斷地迅速找到所需模塊和函數(shù)的使用方法。

通用幫助函數(shù)help()

在python命令行中鍵入help(),可以看到:

>>> help()

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help>

進(jìn)入help幫助文檔界面,根據(jù)屏幕提示可以繼續(xù)鍵入相應(yīng)關(guān)鍵詞進(jìn)行查詢,繼續(xù)鍵入modules可以列出當(dāng)前所有安裝的模塊:

help> modules
Please wait a moment while I gather a list of all available modules...
AutoComplete        _pyio               filecmp             pyscreeze
AutoCompleteWindow  _random             fileinput           pytweening
......        
Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

模塊幫助查詢

查看.py結(jié)尾的普通模塊help(module_name)

例如要查詢math模塊的使用方法,可以如下操作:

>>> import math
>>> help(math)
Help on built-in module math:
NAME
    math
DESCRIPTION
    This module is always available.  It provides access to the
    mathematical functions defined by the C standard.
FUNCTIONS
    acos(...)
        acos(x)
        Return the arc cosine (measured in radians) of x.
...
>>>

查看內(nèi)建模塊sys.bultin_modulenames

>>> import sys>>> sys.builtin_module_names
('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', ... 'zlib')
>>>

查詢函數(shù)信息

查看模塊下所有函數(shù)dir(module_name)

如我們需要列舉出math模塊下所有的函數(shù)名稱

>>> dir(math)
['__doc__', '__loader__', '__name__',...]
>>>

以上是查看python模塊的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI