🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Docstrings (Documentation Strings) are special strings used to document Python code. They provide a description of what a module, class, function or method does.
🌐
Programiz
programiz.com › python-programming › docstrings
Python Docstrings (With Examples)
Python docstrings are the string literals that appear right after the definition of a function, method, class, or module.
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.5 documentation
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.
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - Python documentation string, commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function.
🌐
AskPython
askpython.com › python › python-docstring
Python Docstring - AskPython
February 16, 2023 - Python function docstring should specify the behavior, input arguments, return types, and exceptions. If there are specific restrictions when the function can be called, it should be specified in the function docstring.
🌐
Stack Abuse
stackabuse.com › python-docstrings
Python Docstrings
August 23, 2023 - The article mentioned above briefly introduced the concept of docstrings which is a way to create documentation for your Python code from within the code. This in-code documentation works for modules, classes, methods, and functions, and it is the preferred way to document all Python code.
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python documentation
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.
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › python › python docstring: documenting and introspecting functions
Python Docstring: Documenting And Introspecting Functions
April 1, 2025 - “A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of the object.” · Docstrings are defined with triple-double ...
🌐
Wikipedia
en.wikipedia.org › wiki › Docstring
Docstring - Wikipedia
December 19, 2025 - The following Python code declares docstrings for each program element: """The module's docstring""" class MyClass: """The class's docstring""" def my_method(self): """The method's docstring"""
🌐
PythonForBeginners.com
pythonforbeginners.com › home › python docstrings
Python Docstrings - PythonForBeginners.com
August 28, 2020 - The following Python file shows the declaration of docstrings within a python source file: """ Assuming this is file mymodule.py, then this string, being the first statement in the file, will become the "mymodule" module's docstring when the file is imported. """ class MyClass(object): """The class's docstring""" def my_method(self): """The method's docstring""" def my_function(): """The function's docstring"""
🌐
Real Python
realpython.com › documenting-python-code
Documenting Python Code: A Complete Guide – Real Python
July 17, 2026 - Class docstrings should contain the following information: ... The class constructor parameters should be documented within the __init__ class method docstring. Individual methods should be documented using their individual docstrings.
🌐
pyOpenSci
pyopensci.org › python-package-guide › documentation › write-user-documentation › document-your-code-api-docstrings.html
Document the code in your package’s API using docstrings — Python Packaging Guide
Package APIs consist of functions, classes, methods and attributes that create a user interface. In Python, a docstring refers to text in a function, method or class that describes what the function does and its inputs and outputs.
🌐
Reddit
reddit.com › r/learnpython › advice on writing some docstrings
r/learnpython on Reddit: Advice on writing some docstrings
May 6, 2022 -

I need to write docstrings for every method and property in this file:

https://github.com/golemfactory/yapapi/blob/master/yapapi/services/service_runner.py

A couple questions.

Should you write a docstring for an init method? I suppose it depends? This one seems self explanatory. Should I just state what the code does? “ServiceRunner class is initialized with four parameters: job, instance, instance_tasks, and stopped.”

I could explain what each of those do. I actually have some questions about them. “Job” is clearly passed the string “job”, so I don’t understand the later call “job.id” - the string returns an ID?

As for: self._instances: List[Service] = [] - how can you pass an entire statement as an attribute? They convert “Service” to a list but then assign it as an empty list… will the result be the list of services or the empty list?

Just that for now. Please let me know if you understand this a bit better than I do.

Thanks very much

Top answer
1 of 3
4
You can configure sphinx if that's what you are using for documentation to document __init__ method separately, however, the default is to use the documentation for the class to describe that. I don't like the default and usually configure sphinx not to do that, but you need not do the same. If you are going with defaults, then the class documentation may include :ivar : for class fields. You can also include :param <__init__ param>: in that documentation to document parameters supplied to __init__. The other thing: you misinterpreted type annotation to have some procedural semantics. What it means is that self._instance is believed to have a type of list with elements being of type Service (it's actually wrong, because the code doesn't need it to be a list, it just needs to be something that has methods copy() and append(), but this kind of mistake is very typical of Python as of late.
2 of 3
3
When writing docstrings you should adhere to some style. First see if there exists any existing style guides for the project you are working on. If not then pick a style and stick to it. I prefer Google's docstring style https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings Also note that plugins helps a bunch. Whenever I need a docstring I just hit ,cn and it inserts a boilerplate docstring in the current function. These also exists for VScode, pycharm, etc. Just google a bit for your editor. For examples see for instance https://github.com/psf/requests/blob/main/requests/adapters.py
🌐
FavTutor
favtutor.com › blogs › docstring-python
Python Docstring: How to Write Docstrings? (with Examples)
June 6, 2023 - A docstring has a straightforward format: it is a string surrounded by triple quotes that appear as the first statement of a function, method, or module. Here is an illustration of a Python function's documentation string:
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
Class docstrings must be placed directly below the declaration, and indented according to the code scope: class MyClass(object): """Summary of MyClass. Parameters ---------- a : `str` Documentation for the ``a`` parameter. """ def __init__(self, a): pass · The __init__ method never has a docstring since the class docstring documents the constructor.
🌐
Real Python
realpython.com › how-to-write-docstrings-in-python
How to Write Docstrings in Python – Real Python
August 25, 2025 - Python docstrings are string literals that show information regarding Python functions, classes, methods, and modules, allowing them to be properly documented.
🌐
Real Python
realpython.com › ref › glossary › docstring
docstring | Python Glossary – Real Python
In Python, a docstring is a string literal that occurs as the first statement in a module, function, class, or method definition and works as the code’s documentation.
🌐
Mimo
mimo.org › glossary › python › docstrings
Python Docstrings: Syntax, Usage, and Examples
Every function should have a docstring explaining its purpose, parameters, and return value. This is especially valuable for Python functions that accept args or keyword arguments (kwargs). ... Docstrings in classes describe their attributes and methods.