What are the most common Python docstring formats?
There are several common formats for Python docstrings, including:
- The "one-liner" format, which is a single line of text that briefly describes the function or class. Example:
def my_function():
"""This function does something."""
- The "epytext" format, which is a markup language that can be used to create structured documentation. Example:
def my_function(arg1, arg2):
"""
This function does something.
@param arg1: The first argument.
@param arg2: The second argument.
@return: The result of the function.
"""
Watch a video course
Python - The Practical Guide
- The "reStructuredText" format, which is a markup language that is similar to epytext, but is more widely used in Python documentation. Example:
def my_function(arg1, arg2):
"""
This function does something.
:param arg1: The first argument.
:param arg2: The second argument.
:return: The result of the function.
"""
- Numpy/Google format
def my_function(arg1, arg2):
"""
This function does something.
Parameters
----------
arg1 : int
The first argument.
arg2 : int
The second argument.
Returns
-------
int
The result of the function.
"""
It's worth noting that the most commonly used format is the Numpy/Google format which is widely used in scientific and data science communities.