Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the docstring from a function

Tags:

python

People also ask

How do you print the docstring documentation string of the input function?

just use print(input. doc)

How do you check the documentation of a function in python?

Python help() function is used to get the documentation of specified module, class, function, variables etc. This method is generally used with python interpreter console to get details about python objects.

What is function docstring in python?

A Python docstring is a string used to document a Python module, class, function or method, so programmers can understand what it does without having to read the details of the implementation. Also, it is a common practice to generate online (html) documentation automatically from docstrings.

What is print (__ doc __)?

The print(__doc__) command simply re-uses that documentation string to write it to your terminal each time you run the script, and any other python tool (like the interactive interpreter help() function, for example) can introspect that same value.


Interactively, you can display it with

help(my_func)

Or from code you can retrieve it with

my_func.__doc__

You can also use inspect.getdoc. It cleans up the __doc__ by normalizing tabs to spaces and left shifting the doc body to remove common leading spaces.


On ipython or jupyter notebook, you can use all the above mentioned ways, but i go with

my_func?

or

?my_func

for quick summary of both method signature and docstring.

I avoid using

my_func??

(as commented by @rohan) for docstring and use it only to check the source code