+ 2
Are 'Docstrings' same as 'Comments' in Python? Or do they have any special purpose?
As far as I understand docstrings are somewhat similar to multi line comments used in other programming languages, but this is the part which I don't understand: "Unlike conventional comments, docstrings are retained throughout the runtime of the program. This allows the programmer to inspect these comments at run time."
3 Answers
+ 4
What I got from google:
"A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object. All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings."
+ 1
You can use it as comments or that part of your coding related works which will not be a part of code but it will work as explanations or comments.
0
the piece of doc string will show up in the ide when you type the associated class/method.
the comment won't