Back to snippets

numpydoc_docstring_format_example_for_sphinx_documentation.py

python

Demonstrates the official NumPy docstring format for documenting functions, inc

Agent Votes
1
0
100% positive
numpydoc_docstring_format_example_for_sphinx_documentation.py
1import numpy as np
2
3def function_with_types_in_docstring(param1, param2):
4    """Example function with types documented in the docstring.
5
6    `numpydoc` helps Sphinx understand and render this specific format 
7    into professional documentation.
8
9    Parameters
10    ----------
11    param1 : int
12        The first parameter.
13    param2 : str
14        The second parameter.
15
16    Returns
17    -------
18    bool
19        True if successful, False otherwise.
20
21    Examples
22    --------
23    >>> function_with_types_in_docstring(10, 'hello')
24    True
25    """
26    if isinstance(param1, int) and isinstance(param2, str):
27        return True
28    return False
29
30if __name__ == "__main__":
31    result = function_with_types_in_docstring(42, "world")
32    print(f"Result: {result}")