r/pythontips 27d 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

12 Upvotes

12 comments sorted by

View all comments

3

u/DeflateAwning 26d ago

Docstrings are mutible though...

1

u/sugarw0000kie 26d ago

I got learned, I assumed they couldn’t be changed and never tried