Create documentation comments
Place the caret after the declaration of a function you want to document.
Type opening triple quotes, and press Enter, or Space.
Add meaningful description of parameters and return values.
tip
Mind the following:
Generation of docstrings on pressing Space after typing opening triple quotes only works when the checkbox Insert pair quote is cleared in the page Smart Keys of the editor settings.
If you rename a parameter of a function, PyCharm will correspondingly update the tag in documentation comment.
Place the caret somewhere within the function you want to document.
Press AltEnter to show the available intention actions.
Choose Insert documentation string stub:
PyCharm generates documentation comment stub according to docstring format, selected in the Python Integrated Tools page.
Consider the following function:
def handle(self, myParam1, myParam2):
Open settings CtrlAlt0S and navigate to Tools | Python Integrated Tools.
In the Docstring format dropdown, select Epytext:
![Changing the type of docstrings Changing the type of docstrings](https://resources.jetbrains.com/help/img/idea/2023.2/py_change_docstring_type.png)
Then type the opening triple double-quotes and press Enter or Space. PyCharm generates a documentation comment stub in Epytext format:
"""
@param self:
@param myParam1:
@param myParam2:
@return:
"""
Go back to the Python Integrated Tools page in settings (CtrlAlt0S) and switch Docstring format to reStructuredText. Then type the opening triple double-quotes and press Enter or Space. PyCharm generates a documentation comment stub in reStructuredText format:
"""
:param self:
:param myParam1:
:param myParam2:
:return:
"""
You can use markup for text formatting, as well as substitutions, bulleted lists, links, code blocks, and tables:
![Example of text formatting in a function docstring Example of text formatting in a function docstring](https://resources.jetbrains.com/help/img/idea/2023.2/py_docstring_formatting.png)
Thanks for your feedback!