+ 4
What is the difference between Docstrings and Comments?
What is the purpose of Docstrings? Is Docstrings python's multi-line comment?
3 Réponses
+ 5
docstrings can be viewed when the program is running, comments can't be (they are ignored). so, if you have notes that are important to clarify aspects of your program, use a docstring. if ypu just want to explain your code (to other programmers), use comments.
+ 4
docstring of function can be view by run help(function_name) in interpreter after the module is imported, while comment only can be access by open up the source code
+ 1
You can see the memo in the docstrings easily by running "help" function, but you can see comment only in the source code.
So, docstrings is good to explain a detailed description of function, class or module. You can also embed small test in docstrings by "doctest"!