help() Method

Learn how to use Python's help() function to view documentation for objects, modules, and classes.

Loading...
help() Method

The help() function in Python is used to display documentation about objects such as classes, functions, methods, and modules.

It’s a quick way to explore Python’s built-in objects or even your own custom classes.

Example 1: Getting Help on a Built-in Class

# Use help() to get information about the str class
help(str)

Output:

Help on class str in module builtins:
 
class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |
 |  Create a new string object from the given object.

Example 2: Getting Help on a Function

help(len)

Output:

Help on built-in function len in module builtins:
 
len(obj, /)
    Return the number of items in a container.

Example 3: Using help() on a User-defined Class

class Person:
    """Represents a person with a name and age."""
 
    def __init__(self, name, age):
        self.name = name
        self.age = age
 
help(Person)

This displays the class docstring and details about its methods.


Example 4: Using help() Without Arguments

help()

This opens Python’s interactive help utility, where you can type the name of any object or module to get documentation.


Notes:

  • help() relies on docstrings (""" ... """) for displaying documentation.
  • Writing clear docstrings for your functions and classes makes help() more useful.

👉 Next tutorial: Python super() Function

Support my work!