當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python help()用法及代碼示例

Python help() 函數用於獲取與調用過程中傳遞的對象相關的幫助。它接受一個可選參數並返回幫助信息。如果沒有給出參數,它會顯示 Python 幫助控製台。它內部調用python的幫助函數。

簽名

help(object)

參數

object:它可以是我們想要獲得幫助的任何對象。

返回

它返回對象的信息。

讓我們看一些 help() 函數的例子來理解它的函數。

Python help() 函數示例 1

# Python help() function example
# Calling function
info = help() # No argument
# Displaying result
print(info)

輸出:

Welcome to Python 3.5's help utility!

Python help() 函數示例2

# Python help() function example
# Calling function
info = help(1) # integer value
# Displaying result
print(info)

輸出:

Help on int object:

class int(object)
 |  int(x=0) -> integer
 |  int(x, base=10) -> integer
 |  
 |  Methods defined here:
 |  
 |  __abs__(self, /)
 |      abs(self)
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __and__(self, value, /)
 |      Return self&value.;

Python help() 函數示例3

如果對象是一個列表,它會打開列表模塊和它的類。查看輸出。

# Python help() function example
# Calling function
info = help(list) # integer value
# Displaying result
print(info)

輸出:

Help on class list in module builtins:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items
 |  
 |  Methods defined here:
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __delitem__(self, key, /)
 |      Delete self[key].

Python help() 函數示例 4

如果沒有幫助或信息,它會向控製台顯示一條消息並返回 None。

# Python help() function example
# Calling function
info = help("Javatpoint") # integer value
# Displaying result
print(info)

輸出:

No Python documentation found for 'Javatpoint'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

None






相關用法


注:本文由純淨天空篩選整理自 Python help() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。