voidex/20-29 Areas/20 Programming/20.01 Python/docStrings.md

969 B

title tags aliases
docstrings
python
functions
comments
documentation
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

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 for conventions.

[!info] Related Notes
functions
comments
pythonSyntaxOverview