__doc__ — Easy Examples
The docstring of a module, class, method, or function
Accessing __doc__
How to access and use __doc__.
python
# __doc__ holds the docstring def greet(name): """Greet someone by name.""" return f"Hello, {name}!" print(greet.__doc__) print(list.__doc__[:100])
__doc__ is a special attribute that the docstring of a module, class, method, or function.
__doc__ in practice
Using __doc__ in everyday code.
python
# More __doc__ examples print("__doc__ is a special Python attribute") # Every object has certain dunder attributes obj = object() attrs = [a for a in dir(obj) if a.startswith("__")] print(f"object has {len(attrs)} dunder attributes")
Understanding __doc__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground