Signup/Sign In

The help function in Python

Posted in Programming   LAST UPDATED: DECEMBER 11, 2019

    We have all googled for specific in-built method's documentation whenever we get stuck while coding in any programming language. But what if we need to check too many functions for a small programming assignment/requirement? It gets clumsy, and this is where the help method comes into the picture.

    In this post, we will understand the help method in Python and how it can be used effectively to get all the information about specific objects in Python.


    What is the help method?

    It is a method that calls the built-in Python system to fetch details regarding a specific object. This object is passed as a parameter to the help method.

    Syntax of help method:

    help(object)

    The help method takes in maximum one argument and returns information about that argument(argument is generally the name of any Python keyword, function or object). The object refers to the entity on which more information/help is needed. In case this parameter is not provided (it is optional), it takes the user to the interactive Python interpreter.

    We will look at three different use cases of the help method namely:

    • Using help by passing an object as an argument,

    • Using help by passing a string as an argument,

    • Using help without passing any argument.




    1. Passing an object as an argument

    The argument passed is not a string, but an object or a data structure about which more information is required, and once it is passed to the help method, information about it is displayed on the console.

    Below are a few examples demonstrating the same:

    help method in python




    2. Passing a string as an argument

    When the argument passed to the help method is a string, that string is checked for in modules, functions, classes, keywords and documentation topics.

    If the string matches any one of these, the help page for that string is displayed on the console.

    help method in python




    3. Passing no parameters at all

    When no parameter is passed to the help method, Python's interactive help system starts up on the console. Here, the user can enter the name of the entity on which they need more details (This could be a function, module, class, or any other Python object)

    help method in python

    help method in python




    4. Quitting the Python interpreter

    Once no argument is passed to the help method, it starts in the interactive mode and if the keyword quit is typed on the console, and the enter key is clicked, it closes the help tab.

    help > quit

    help method in python




    Conclusion

    In this post, we saw the significance of the help method in Python along with its usage. Don't forget to try using the help method on your own system.

    About the author:
    I love writing about Python and have more than 5 years of professional experience in Python development. I like sharing about various standard libraries in Python and other Python Modules.
    Tags:Python
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS