Search code examples
pythondocstring

Getting the docstring from a function


I have the following function:

def my_func():
    """My docstring is both funny and informative"""
    pass

How do I get access to the docstring?


Solution

  • Interactively, you can display it with:

    help(my_func)
    

    Or from code you can retrieve it with (surround it with print(.) to get a formatted output):

    my_func.__doc__