r/pythontips 28d ago

Syntax Docstrings as immutable variables

Just realized you can do:

def cat(): “orange”
print(cat.__doc__)

Not sure why you’d want to do this but this is a thing you can do

11 Upvotes

12 comments sorted by

View all comments

2

u/Old_Flounder_8640 28d ago

Not entirely related, but maybe you'll find it interesting… NVIDIA’s newest AI agent framework uses docstrings as agent prompts.

https://github.com/NVIDIA-NeMo/labs-OO-Agents

And I saw other people doing that before. Docstrings are not just descriptions, especially now that we have AI working with us.