---
title: docstrings
tags:
  - python
  - functions
  - comments
  - documentation
aliases:
  - triple quotes
  - function docs
---

> [!note] Concept  
> A **docstring** is a special string that documents a function, class, or module. It should be the first statement inside a function body and use triple double-quotes.
> 
> > [!example] Multi-line Docstring  
> > ```python
> > def complex(real=0.0, imag=0.0):
> >     """Form a complex number.
> > 
> >     Keyword arguments:
> >     real -- the real part (default 0.0)
> >     imag -- the imaginary part (default 0.0)
> >     """
> >     return complex(real, imag)
> > ```
> 
> > [!important] Best Practices  
> > - Use triple double quotes: `""" ... """`  
> > - Keep it concise and clear — first line should summarize purpose.  
> > - Follow [PEP 257](https://peps.python.org/pep-0257/) for conventions.  
> 
> > [!info] Related Notes  
> > [[functions]]  
> > [[comments]]  
> > [[pythonSyntaxOverview]]  
> 