+ 2
Docstrings??? vs Comments???
Do docstrings and #symbol comments have the same purpose???
1 Answer
+ 6
Docstrings, on top of their use as multiline comments, can be used to generate documentation about your code when use right after a def line.
def add(a, b)
"""
Add a to b and
return the sum
"""
return a + b
Using help(add) in interactive mode will print the docstring. Some IDEs may make use of it as well. You can extract all docstrings with some tools and generate documentation automatically that way.