Help function in Python

Python provides a built-in help() function that gives you access to the interactive help system. This function displays documentation for modules, functions, classes, and other objects directly in your Python environment.

Syntax

help(object)
help('string')
help()

Where:

  • object − Any Python object (function, module, class, etc.)
  • 'string' − String name of a module or keyword
  • help() − Starts interactive help mode

Getting Help on Built-in Functions

You can get help on any built-in function by passing it directly to help() ?

help(len)
Help on built-in function len in module builtins:

len(obj, /)
    Return the number of items in a container.

Getting Help on Modules

Pass the module name as a string to get comprehensive documentation ?

help('math')
Help on built-in module math:

NAME
    math

DESCRIPTION
    This module provides access to the mathematical functions
    defined by the C standard.

FUNCTIONS
    acos(x, /)
        Return the arc cosine (measured in radians) of x.
    ...

Getting Help on Data Types

You can also get help on Python data types and their methods ?

help(str.upper)
Help on method_descriptor:

upper(self, /)
    Return a copy of the string converted to uppercase.

Interactive Help Mode

Calling help() without arguments starts interactive help mode. Type 'quit' to exit ?

help()

# Interactive session starts
# help> len
# help> quit

Getting Help on User-Defined Objects

The help() function also works with your own functions and classes ?

def greet(name):
    """Return a greeting message for the given name."""
    return f"Hello, {name}!"

help(greet)
Help on function greet in module __main__:

greet(name)
    Return a greeting message for the given name.

Practical Tips

Usage Example Purpose
Built-in function help(print) Quick function reference
Module documentation help('os') Comprehensive module info
Method help help(list.append) Specific method details
Interactive mode help() Exploratory browsing

Conclusion

The help() function is an essential tool for Python development, providing instant access to documentation. Use it to explore built-in functions, modules, and your own code's documentation.

Updated on: 2026-03-15T19:11:19+05:30

278 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements