๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Python Beginner

What is Docstring?

A string literal placed as the first statement in a module, class, or function to document its purpose and usage.

Docstrings use triple quotes and describe what code does, its parameters, return values, and examples. They are accessible at runtime via __doc__ attribute and used by help() function, IDE tooltips, and documentation generators.

Common formats include Google style, NumPy style, and reStructuredText (Sphinx). Tools like Sphinx generate beautiful HTML documentation from docstrings. PEP 257 defines docstring conventions.

Related Terms

Enum
A built-in class for creating enumerated constants โ€” named groups of related values that improve code readability.
Generator
A function that yields values one at a time using the yield keyword, enabling memory-efficient iteration over large datasets.
Python Interpreter
The program that reads and executes Python code, translating it into machine instructions at runtime.
Requests Library
An elegant HTTP library for Python that simplifies making web requests with a human-friendly API.
Python Metaclass
A class whose instances are classes themselves โ€” the class of a class that controls how classes are created and behaved.
Python Iterator Protocol
The interface requiring __iter__() and __next__() methods, enabling objects to be used in for loops and other iteration contexts.
View All Python Terms โ†’