Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python help() Function



The Pythonhelp() function is a built-in help system that can be invoked on any object, class, function, or module to collect more information about it.

If an argument is passed to this function, a help page on that argument is generated. In the case, when no arguments are passed an interactive help system is shown on the interpreter console. This function is one of thebuilt-in functions, you do not need to import any built-in module to use this method.

Syntax

The syntax of the pythonhelp() function is as follows −

help(object)

Parameters

The pythonhelp() function accepts a single parameter −

  • object − This parameter specifies an object for which we need help.

Return Value

The pythonhelp() function returns the information related to the passed object.

help() Function Examples

Practice the following examples to understand the use ofhelp() function in Python:

Example: Use of help() Function

The following example shows the basic usage of the Pythonhelp() function. In this, we are passing the built-in function "print()" as an argument to the help() function which will display the brief description of the function.

help(print)

On executing the above program, the following output is generated −

Help on built-in function print in module builtins:print(...)    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)    Prints the values to a stream, or to sys.stdout by default.    Optional keyword arguments:    file:  a file-like object (stream); defaults to the current sys.stdout.    sep:   string inserted between values, default a space.    end:   string appended after the last value, default a newline.    flush: whether to forcibly flush the stream.

Example: Get Detail of a Module Using help() Function

If we want to show the details of aPython built-in module, we simply need to import it and pass that module to the help() function as a parameter value.

import mathhelp(math)

The following is the output obtained by executing the above program −

Help on built-in module math:NAME    mathDESCRIPTION    This module provides access to the mathematical functions    defined by the C standard.

Example: Get Detail of a Class Using help() Function

Thehelp() function returns the description of a class if we pass the class name as an argument to it. It will display the method and otherattributes of the passed class.

class NewClass:   def firstExample(self):      """      This is an example of NewClass.      """      passhelp(NewClass)

The following output is obtained by executing the above program -

Help on class NewClass in module __main__:class NewClass(builtins.object) |  Methods defined here: |   |  firstExample(self) |      This is an example of NewClass.

Example: Get Detail of a Local Methods Using help() Function

With the help ofhelp() function, we can also display the description of a local method as illustrated in the below example.

class NewClass:   def firstExample(self):      """      This is an example of NewClass.      """      passnewObj = NewClass()help(newObj.firstExample)

The above program, on executing, displays the following output −

Help on method firstExample in module __main__:firstExample() method of __main__.NewClass instance    This is an example of NewClass.
python_built_in_functions.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp