国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python help()函數用法詳解

2019-11-25 18:29:36
字體:
來源:轉載
供稿:網友

help函數是python的一個內置函數(python的內置函數可以直接調用,無需import),它是python自帶的函數,任何時候都可以被使用。help函數能作什么、怎么使用help函數查看python模塊中函數的用法,和使用help函數時需要注意哪些問題,下面來簡單的說一下。

一、help()函數的作用
在使用python來編寫代碼時,會經常使用python自帶函數或模塊,一些不常用的函數或是模塊的用途不是很清楚,這時候就需要用到help函數來查看幫助。
這里要注意下,help()函數是查看函數或模塊用途的詳細說明,而dir()函數是查看函數或模塊內的操作方法都有什么,輸出的是方法列表。
二、怎么使用help函數查看python模塊中函數的用法
help()括號內填寫參數,操作方法很簡單。例如:

復制代碼 代碼如下:
>>> help('dir')
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函數查看幫助實例

在寫help()函數使用方法時說過,括號中填寫參數,那在這里要注意參數的形式:

1、查看一個模塊的幫助

復制代碼 代碼如下:
>>>help('sys')

之后它回打開這個模塊的幫助文檔
2、查看一個數據類型的幫助
復制代碼 代碼如下:
>>>help('str')

返回字符串的方法及詳細說明
復制代碼 代碼如下:
>>>a = [1,2,3]
>>>help(a)

這時help(a)則會打開list的操作方法
復制代碼 代碼如下:
>>>help(a.append)

會顯示list的append方法的幫助

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潍坊市| 呼和浩特市| 汝州市| 莱阳市| 安龙县| 洮南市| 怀仁县| 乌拉特前旗| 吕梁市| 讷河市| 姚安县| 临城县| 东至县| 泸溪县| 益阳市| 鹤山市| 兰西县| 渭源县| 怀来县| 道真| 灵川县| 南陵县| 卓尼县| 盘锦市| 巩义市| 西林县| 上饶县| 汤原县| 百色市| 香格里拉县| 天峻县| 卢氏县| 晋州市| 屏山县| 连南| 澄城县| 梁山县| 陇川县| 石嘴山市| 乐至县| 黄龙县|