Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
wb_sunny

Python help() method

Python Help() Method

Hey, folks! In this article, we will be focusing on a important explanatory function in Python — Python help() function.


Need of the help() method

While coding in a particular programming language, it is very essential for us to know the basic documentation of the framed language. This is when the help() function comes into picture.

This function provides us with the basic documentation of Python language. It gives us the information about the methods and instances associated with a particular method or class.

The help() method works with keywords, Classes, functions and modules to help us gain the basic terminologies, instances and working attached with it respectively.

Usually the help() method is used alongside the Python interpreter to gain access to the underlying details about Python objects passed to it as a parameter.


Working of Python help() method

As mentioned above, the help() method provides information about the Python objects passed to it.

If the help() function is mentioned without any parameter, it starts the interpreter console wherein we can mention any module, objects, class, etc to avail the documentation about the same.

Example :

help()

Output:

Python Help
help() function

Python help() function with a Class

The help function can be feeded with customized or pre-defined parameters to work with. We can create a customized class and pass it to the help() function to examine the documentation provided by the function.

Example:

class Info:
    lang = "Python"
    name = "JournalDev"
obj = Info()
help(Info)

We have created an user-defined class and passed it to the help() function. The help() function has returned the necessary documentation of the class ‘Info’.

Output:

Help on class Info in module __main__:

class Info(builtins.object)
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  lang = 'Python'
 |  
 |  name = 'JournalDev'

Python help() function with a function

The help() function helps us to access the syntax, parameter list and the description about any function passed to it using the below command.

Syntax:

help('function-name')

Example 1:

help('getattr')

Output:

Python help() Function With Function getattr()
help() With Function getattr()

Example 2:

help('map')

Output:

Python help() Function With Function map()
help() With Function map()

Python help() function with a module

We can gain information about the module using the help() function. When a module is passed to the help() function, it provides the documentation in terms of the version, file location, contents of the module, and data associated with it.

Syntax:

help('module-name')

Example:

help('seaborn')

Output:

Python help() Function With Module Seaborn
Help on Module Seaborn

The help() function with a keyword

On passing a Python keyword as parameter to the help() function, the function returns the documentation in terms of the class of the keyword, the methods associated with it, etc.

Syntax:

help('keyword-name')

Example 1:

help(True)

Output:

Python help() Function With Keyword True
help() function With Keyword True

Example 2:

help(int)

Output:

Python help() Function With Keyword int
help() Function With Keyword int

Conclusion

By this we have come to the end of this topic. We have understood the need and working of the help() function. I hope this concept is clear to all the readers.

Please feel free to comment, in case you happen to come across any doubt.


References