Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python help() Function

Python help() Function

Python3 Built-in Functions Python3 built-in function


help() is a built-in Python function that gets help information about built-in functions, modules, objects, and so on.

When you have questions about how to use a function or module,help() is the best query tool. It shows detailed docstrings, helping you understand a function's purpose, parameters, and return value.

Word meaning: help means "help", used to obtain documentation information.


Basic syntax and parameters

Syntax format


help(object)
help('topic')

Parameter Description

- Type: any object (function, class, module, etc.) - Description: the object whose help information is wanted. - Type: string - Description: a topic name, such as a module name, function name, or keyword.

Function description

- Query function usage - Query module features - Learn Python syntax

Example

Example 1: viewing help for a function

Example

View help for the len function

help

(

len

)

Output:

Help on built-in function len in module builtins:

len(obj, /)

    Return the number of items in a container.

View help for the print function

help

(

print

)

Output:

Help on built-in function print in module builtins:

print(...)

    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

    Prints the values to a stream or to sys.stdout by default.

View help for an object

help

(

[

]

.

append

)

Output:

Help on method_descriptor:

append(self, object, /) method of builtins.list instance

    L.append(object) -> None -- append object to end

Code analysis:

  1. Pass the function name directly (without parentheses) to view help.
  2. Help information includes the function signature, parameter descriptions, and a description of its functionality.
  3. For methods, help can also be obtained through the object.

Example 2: viewing help for modules and topics

Example

View help for a module

import

os

help

(

os

)

Shows the detailed documentation of the os module, including descriptions of all functions and constants

View a specific topic

help

(

"modules"

)

Lists all available modules

help

(

"keywords"

)

Lists all Python keywords

help

(

"assert"

)

Shows the usage of the assert statement

Code analysis:

Example 3: using help in a script

Example

Interactive use (most common)

>>> help(list)

Shows all methods of the list class

View help for data types

help

(

int

)

   

Integer type

help

(

str

)

   

String type

help

(

dict

)

 

Dictionary type

help

(

tuple

)

 

Tuple type

View help for exceptions

help

(

ZeroDivisionError

)

help

(

ValueError

)

View syntax help

help

(

"with"

)

help

(

"for"

)

help

(

"if"

)

Expected output:

Running the code above in a real interactive Python environment displays detailed help documentation.

help() is one of the most powerful tools for learning Python; it is recommended to use it often in daily programming.


Python3 Built-in Functions Python3 built-in function