+ 4

What is the difference between Docstrings and Comments?

What is the purpose of Docstrings? Is Docstrings python's multi-line comment?

9th Aug 2016, 5:51 AM
Nadir Nour
Nadir  Nour - avatar
3 ответов
+ 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.
9th Aug 2016, 12:21 PM
Jasper Ro
Jasper Ro - avatar
+ 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
25th Nov 2016, 4:06 PM
skycc
skycc - avatar
+ 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"!
31st Jan 2018, 4:17 PM
mita vivi makiko