Skip to main content

Python help() Function

The help() function in Python is a built-in function that provides interactive documentation on modules, functions, classes, and keywords.

  • When called with an argument, it attempts to display the documentation for that argument.
  • Otherwise, it enters an interactive mode where the user can type the name of any Python object to get help on it

Syntax

help(object)

help() Parameters

Python help() function parameters:

ParameterConditionDescription
objectOptionalAny Python object for which help is needed. If omitted, the interactive help system starts

help() Return Value

Python help() function does not return a value. Instead, it prints the documentation for the given object to the console or starts the interactive help system.

Examples

Example 1: Basic Usage

Running help() without an argument opens the interactive help system, allowing you to enter the names of Python objects to get help on them

help()

Example 2: Getting Help on a Built-in Function

This command will display the documentation for the built-in print function, including its signature and a brief description of what it does:

help(print)

Example 3: Getting Help on a User-Defined Class

Consider the following Student class: calling help(Student) will show the docstring of the Student class, listing its constructor, attributes, and methods along with their descriptions:

class Student:
"""Represents a student."""
def __init__(self, name, grade):
self.name = name
self.grade = grade

def study(self, hours):
"""Simulates studying for a certain amount of hours."""
pass

help(Student)

Example 4: Using help() in an Interactive Session

In an interactive Python session, you can use help() to get information about any object, such as the sqrt function from the math module:

>>> import math
>>> help(math.sqrt)