How to print your python functional documentation

I have been looking for an answer for a long time. Let's say I wrote a function in python, and I made a brief documentation of what this function does. Is there a way to print function documentation from the main? Or from the function itself?

+4
source share
1 answer

You can use or print . prints a more detailed description of the object, and contains only the line of documentation that you defined with triple quotes at the beginning of your function. help()__doc__help()__doc__""" """

For example, using __doc__explicitly in a built-in function sum:

print(sum.__doc__)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers

When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.

, Python , , __doc__ :

def foo():
    """sample doc"""
    print(foo.__doc__)

foo()  # prints sample doc

, __doc__, .

, help() sum:

help(sum)

:

Help on built-in function sum in module builtins:

sum(iterable, start=0, /)
    Return the sum of a 'start' value (default: 0) plus an iterable of numbers

    When the iterable is empty, return the start value.
    This function is intended specifically for use with numeric values and may
    reject non-numeric types.

, docstring.

+3

Source: https://habr.com/ru/post/1620004/


All Articles