Reading Time: 1 minutes
Docstrings in Python
You can provide a helpful description of your functions, classes, modules in form of docstrings. Documentation strings need to be the first line of the body of the function, class or module. These helpful strings can be viewed by calling the dunder doc attribute i.e. __doc__ attribute of the object.
>>> def countdown(): '''This function counts from 3 to 0.''' print(3) print(2) print(1) >>> countdown.__doc__ 'This function counts from 3 to 0.' >>> >>> >>> class Man(): '''A simple Man class.''' def eat(): pass def grow(): pass def sleep(): pass >>> Man.__doc__ 'A simple Man class.'