6 ms·
Note that it is good practice to use "docstrings" in python: def demo(): """I'm a demo. Maybe a few lines of doctests below. """ re
by e12e 10y ago
Note that it is good practice to use "docstrings" in python:
def demo():
"""I'm a demo. Maybe a few lines of
doctests below.
"""
return 42
You can now, for example in ipython do: help(demo) and get the demo.__doc__ back. See also doctests.
So no, they are not comments - they are part of the code -- but they are often used to comment on, and document the code.
docstrings pep:
https://www.python.org/dev/peps/pep-0257/ https://www.python.org/dev/peps/pep-0257/
docstring definition from the python docs:
https://docs.python.org/3.5/glossary.html#term-docstring https://docs.python.org/3.5/glossary.html#term-docstring
doctest:
https://docs.python.org/3.5/library/doctest.html?highlight=docstring https://docs.python.org/3.5/library/doctest.html?highlight=d...
- xapata 10y agoDocstrings are part of the metadata of the object. Comments are not.