Python help() function with Examples | Help function in Python

In the previous article, we have discussed Python String encode() Method with Examples
help() Function in Python:

The help() method invokes or calls Python’s built-in help system.

The Python help function displays documentation for modules, functions, classes, keywords, and so on.

Syntax:

help(object)

Parameters

The help() method only accepts one parameter.

object: This is optional. you want to generate help and support from the given object

For interactive use, the help() method is used. When you need assistance writing Python programs and using Python modules, it is recommended that you try it in your interpreter.

1)Note: It should be noted that object is passed to help() (not a string)

For Example:

Input:

help(list)

Output:

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].
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __getitem__(...)
 |      x.__getitem__(y) <==> x[y]
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __iadd__(self, value, /)
 |      Implement self+=value.
 |  
 |  __imul__(self, value, /)
 |      Implement self*=value.
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __len__(self, /)
 |      Return len(self).
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __mul__(self, value, /)
 |      Return self*value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __reversed__(...)
 |      L.__reversed__() -- return a reverse iterator over the list
 |  
 |  __rmul__(self, value, /)
 |      Return value*self.
 |  
 |  __setitem__(self, key, value, /)
 |      Set self[key] to value.
 |  
 |  __sizeof__(...)
 |      L.__sizeof__() -- size of L in memory, in bytes
 |  
 |  append(...)
 |      L.append(object) -> None -- append object to end
 |  
 |  clear(...)
 |      L.clear() -> None -- remove all items from L
 |  
 |  copy(...)
 |      L.copy() -> list -- a shallow copy of L
 |  
 |  count(...)
 |      L.count(value) -> integer -- return number of occurrences of value
 |  
 |  extend(...)
 |      L.extend(iterable) -> None -- extend list by appending elements from the iterable
 |  
 |  index(...)
 |      L.index(value, [start, [stop]]) -> integer -- return first index of value.
 |      Raises ValueError if the value is not present.
 |  
 |  insert(...)
 |      L.insert(index, object) -- insert object before index
 |  
 |  pop(...)
 |      L.pop([index]) -> item -- remove and return item at index (default last).
 |      Raises IndexError if list is empty or index is out of range.
 |  
 |  remove(...)
 |      L.remove(value) -> None -- remove first occurrence of value.
 |      Raises ValueError if the value is not present.
 |  
 |  reverse(...)
 |      L.reverse() -- reverse *IN PLACE*
 |  
 |  sort(...)
 |      L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __hash__ = None

Explanation:

In this way we get the output which displays the documentation for modules, 
functions, classes, keywords, and so on.

similarly, try out for these

>>help(dict)
>>help(print)
>>help(tuple)
>>help([4,5,6])

If a string is passed as an argument, the name of a module, function, class, method, keyword, or documentation topic is printed, as well as a help page.

2)Note: It should be noted that string is passed as an argument to help()

When a string is passed as an argument, it is looked up as the name of a module, function, class, method, keyword, or documentation topic and a help page is printed.

Check it out for the following Examples.

Input:

help('hello')

Output:

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

similarly, try out for these

>>help('print')
>>help('uvw')

Input:

from math import * 
help('math.pow')

Output:

Help on built-in function pow in math:

math.pow = pow(...)
    pow(x, y)
    
    Return x**y (x to the power of y).

3)Note: It should be noted that no argument is passed to help()

If no arguments are provided, Python’s help utility (interactive help system) is launched on the console.

>>help()

Then, enter the topic name to get help with writing Python programmes and using Python modules.

As an example, Check it out for the following Examples:

help > True
help > 'print'
help > print

To return to the interpreter and exit the help utility, type quit and press enter.

help > quit

Find a Comprehensive Collection of Python Built in Functions that you need to be aware of and use them as a part of your program.