There are two ways to document a module, function, or class in the code itself: comments
and docstrings
.
Docstrings
are more functional, as they can be accessed via the help()
function, while comments
can only be accessed in the source code.
When should comments be used in place of docstrings
?
Docstrings are meant to explain what a function does, in terms of what kinds and types of values it takes and returns, from a user's perspective.
Comments, on the other hand, being in the body of the source code, will only be visible to those actually reading it, and accordingly serve to explain how it does what it does.