Python help()函數(shù)用法詳解
help函數(shù)是python的一個內(nèi)置函數(shù)(python的內(nèi)置函數(shù)可以直接調(diào)用,無需import),它是python自帶的函數(shù),任何時候都可以被使用。help函數(shù)能作什么、怎么使用help函數(shù)查看python模塊中函數(shù)的用法,和使用help函數(shù)時需要注意哪些問題,下面來簡單的說一下。
一、help()函數(shù)的作用
在使用python來編寫代碼時,會經(jīng)常使用python自帶函數(shù)或模塊,一些不常用的函數(shù)或是模塊的用途不是很清楚,這時候就需要用到help函數(shù)來查看幫助。
這里要注意下,help()函數(shù)是查看函數(shù)或模塊用途的詳細說明,而dir()函數(shù)是查看函數(shù)或模塊內(nèi)的操作方法都有什么,輸出的是方法列表。
二、怎么使用help函數(shù)查看python模塊中函數(shù)的用法
help()括號內(nèi)填寫參數(shù),操作方法很簡單。例如:
Help on built-in function dir in module builtins:
dir(...)
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attribut
es
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
三、使用help函數(shù)查看幫助實例
在寫help()函數(shù)使用方法時說過,括號中填寫參數(shù),那在這里要注意參數(shù)的形式:
1、查看一個模塊的幫助
之后它回打開這個模塊的幫助文檔
2、查看一個數(shù)據(jù)類型的幫助
返回字符串的方法及詳細說明
>>>help(a)
這時help(a)則會打開list的操作方法
會顯示list的append方法的幫助
相關(guān)文章
python中zip和unzip數(shù)據(jù)的方法
這篇文章主要介紹了python中zip和unzip數(shù)據(jù)的方法,實例分析了Python中zlib模塊的相關(guān)使用技巧,需要的朋友可以參考下2015-05-05Python 游戲大作炫酷機甲闖關(guān)游戲爆肝數(shù)千行代碼實現(xiàn)案例進階
本篇文章給大家?guī)鞵ython的一個游戲大制作—機甲闖關(guān)冒險,數(shù)千行代碼實現(xiàn)的游戲,過程很詳細,對大家的學習或工作具有一定的借鑒價值,需要的朋友可以參考下2021-10-10python中JSON數(shù)據(jù)格式的詳細使用教程
這篇文章主要給大家介紹了關(guān)于python中JSON數(shù)據(jù)格式的詳細使用,JSON是一種用于存儲和交換數(shù)據(jù)的語法,JSON是文本,使用JavaScript對象表示法編寫,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-02-02Python 用Redis簡單實現(xiàn)分布式爬蟲的方法
本篇文章主要介紹了Python 用Redis簡單實現(xiàn)分布式爬蟲的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11Python urllib、urllib2、httplib抓取網(wǎng)頁代碼實例
這篇文章主要介紹了Python urllib、urllib2、httplib抓取網(wǎng)頁代碼實例,本文直接給出demo代碼,代碼中包含詳細注釋,需要的朋友可以參考下2015-05-05