首頁  >  文章  >  後端開發  >  Python 的 help 函數使用

Python 的 help 函數使用

Guanhui
Guanhui轉載
2020-06-24 18:13:073762瀏覽

Python 的 help 函數使用

help函數是python的內建函數,在python基礎中介紹過什麼是內建函數,它是python自帶的函數,任何時候都可以被使。 help函數能作什麼、怎麼使用help函數查看python模組學習中函數的用法,以及使用help函數時需要注意哪些問題,下面來簡單的說一下。

help函數能做什麼

在使用python來寫程式碼時,會經常使用python呼叫函數、自帶函數或模組,一些不常用的函數或是模組的用途不是很清楚,這時候就需要用到help函數來查看幫助。

這裡要注意下,help()函數是查看函數或模組用途的詳細說明,而dir()函數是查看函數或模組內的操作方法都有什麼,輸出的是方法列表。

怎麼使用help函數來檢視python模組中函數的用法

help( )括號內填入參數,運算方法很簡單。

使用help函數查看幫助時需要注意哪些問題

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

1、查看一個模組的幫助

>>>help('sys')

之後它回打開這個模組的幫助文檔

2、查看一個資料類型的幫助

>>>help('str')

返回字符字串的方法及詳細說明

>>>a = [1,2,3]
>>>help(a)

這時help(a)則會開啟list的操作方法

>>>help(a.append)

會顯示list的append方法的幫助。

實例擴充:

怎麼使用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.

推薦教學:《Python教學

#

以上是Python 的 help 函數使用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:jb51.net。如有侵權,請聯絡admin@php.cn刪除