Docstrings??? vs Comments??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Docstrings??? vs Comments???

Do docstrings and #symbol comments have the same purpose???

25th Oct 2016, 8:50 AM
Manish27
Manish27 - avatar
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.
25th Oct 2016, 10:41 AM
Zen
Zen - avatar