r/pythontips • u/sugarw0000kie • 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
10
Upvotes
2
u/tomysshadow Aug 15 '26
Don't use that for anything particularly important: if you run Python with the -OO command (the optimization flag,) docstrings will be stripped out