triple quoted strings as comments
peter at engcorp.com
Tue Jan 31 02:38:45 CET 2006
> I recently complained elsewhere that Python doesn't have multiline
> comments. i was told to use triple quoted strings to make multiline
> comments. My question is that since a triple quoted string is actually
> a language construct, does it use cause a runtime construction of a
> string which is then discarded, or is the runtime smart enough to see
> that it isn't used and so it doesn't construct it?
Easy enough to find out. Put this in test.py:
'first module comment'
'first func comment'
'and last module comment'
Now do "import test" from the Python prompt, then exit the interpreter
and do "strings test.pyc" on the compiled bytecode.
(The short answer is only the first such comments are kept.)
More information about the Python-list