The help() function is used to get access to the interactive help system. We can use it to find information about  built-in functions, data types, keywords, modules, and even the current Python interpreter environment. The function can especially be useful if you are new to Python as it can help you to quickly find out what a certain function or keyword does. 

There are two ways to use the help() function.

help()
help(argument)
copy

Calling the function using the first syntax( without any argument) pauses the interpreter and starts an interactive help session. In the session, we can type the name of the function, class, keyword, object, etc eg while or a string containing the name e.g "while" and the interpreter will display the relevant help text.

ExampleEdit & Run
help()
copy
Output:
help>input Help on built-in function input in module builtins: input(prompt='', /)     Read a string from standard input.  The trailing newline is stripped. ... help>'while' The "while" statement *********************...

In the second approach,we pass the name when calling the function and the interpreter simply prints the help text without starting an interactive help session.

ExampleEdit & Run
help('if')
copy
Output:
The "if" statement ****************** The "if" statement is used for conditional execution:    if_stmt ::= "if" assignment_expression ":" suite                ("elif" assignment_expression ":" suite)*                ["else" ":" suite] It selects exactly one of the suites by evaluating the expressions one by one until one is found to be true (see section Boolean operations for the definition of true and false); then that suite is executed (and no other part of the "if" statement is executed or evaluated). If all expressions are false, the suite of the "else" clause, if present, is executed. Related help topics: TRUTHVALUE [Finished in 0.03954787738621235s]

What type of objects can we find help on?

  1. Modules: Use help(module) to get information about a module.
ExampleEdit & Run
import string

help( string )
copy
Output:
Help on module string: NAME     string - A collection of string constants....     The following documentation is automatically generated from th...
  1.  Classes and Functions: Use help(class) or help(function) to get information about a specific class or function, respectively.
ExampleEdit & Run
def add(a, b):
   """Prints the sum of two numbers, a and b"""
   print("{} + {} = {}".format(a, b, a+b))

help( add )
copy
Output:
Help on function add in module __main__: add(a, b)     Prints the sum of two numbers, a and b [Finished in 0.038316925056278706s]
  1.  Keywords: Use help('keyword') to get information about a keyword.
ExampleEdit & Run
help('continue')
copy
Output:
The "continue" statement ************************    continue_stmt ::= "continue" "continue" may only occur syntactically nested in a "for" or "while" loop, but not nested in a function or class definition within that loop.  It continues with the next cycle of the nearest enclosing loop. When "continue" passes control out of a "try" statement with a "finally" clause, that "finally" clause is executed before really starting the next loop cycle. Related help topics: while, for [Finished in 0.0393040357157588s]
  1.  Topics: Use help('topics') to get information about topics such as the Python tutorial or how to use the help system. 
ExampleEdit & Run
help('topics')
copy
Output:
Here is a list of available topics.  Enter any topic name to get more help. ASSERTION           DELETION            LOOPING             SHIFTING ASSIGNMENT          DICTIONARIES        MAPPINGMETHODS      SLICINGS...
  1.  Symbols: Use help('symbols') to get information about symbols such as operators or special characters.
ExampleEdit & Run
help('symbols')
copy
Output:
Here is a list of the punctuation symbols which Python assigns special meaning to. Enter any symbol to get more help. !=                  +                   <=                  __ "                   +=                  <>                  ` """                 ,                   ==                  b" %                   -                   >                   b'
  1.  Packages: Use help('package') to get information about a package.
ExampleEdit & Run
help('django')
copy
Output:
Help on package django: NAME     django PACKAGE CONTENTS     __main__     apps (package)