triple quoted strings as comments
André
andre.roberge at gmail.com
Mon Jan 30 20:42:12 EST 2006
dmh2000 wrote:
> 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?
>
> example
>
> def fun(self):
> """doc comment
> comment line 2
> """
>
> x = 1
> y = 2
>
> """does this triple quoted string used as a comment
> cause something to happen at runtime beyond
> just skipping over it? Such as allocation of memory for a string
> or worse yet garbage collection? or not?
> """
> z = x + y
It seems to discard the second triple quoted comment (the first one is
kept around as a doc string).
I created two scripts, one with the second triple quoted string, the
other without. The compiled version is *almost* the same (one byte
difference which, if I am not mistaken, comes from the different
filename embedded in the .pyc file).
30/01/2006 09:34 PM 327 triple.py
30/01/2006 09:35 PM 359 triple.pyc
30/01/2006 09:34 PM 96 triple2.py
30/01/2006 09:35 PM 358 triple2.pyc
André
More information about the Python-list
mailing list