r/pythontips • • Aug 14 '26

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

9 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/softquill4 Sep 24 '26

the /s was doing heavy lifting here lol