What is a Python docstring and what is it for?

Questions & AnswersCategory: PythonWhat is a Python docstring and what is it for?
Geek Boy Staff asked 2 years ago

What is a Python docstring and what is it for?
a. Docstring is a string that appears at the beginning of a module, function, class, or method definition. The docstring passed in this way becomes a special __doc__ attribute for this object. For consistency, use """triple quotes""" around the docstring.

b. Docstring is a Python-built class for creating text documents.

c. Docstring is a string that appears at the beginning of a module, function, class, or method definition. The docstring passed in this way becomes a special __name__ attribute for this object. For consistency, use """triple quotes""" around the docstring.

1 Answers
Lokesh Kumar Staff answered 2 years ago

a. Docstring is a string that appears at the beginning of a module, function, class, or method definition. The docstring passed in this way becomes a special __doc__ attribute for this object. For consistency, use """triple quotes""" around the docstring.
Explanation

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.