Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53606

Re: how does not work nested comment in python?

References <551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com>
Date 2013-09-04 09:55 +0200
Subject Re: how does not work nested comment in python?
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.32.1378281321.5461.python-list@python.org> (permalink)

Show all headers | View raw


2013/9/4  <vnkumbhani@gmail.com>:
> example:
>
> print "hello" # print comment +"world"    => single line comment
> print "hello" '''print comment''' +"world"   => multiple line comment
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
python only has single line comments, which apply from a "#" to the
end of the respective line.
There are some possibilities/workarounds/hacks for "commenting out",
i.e. (temporarily) disabling, parts of the code
if False:
    <indented original code>

Sometimes triple-quoted multiline strings are (mis)used this way
"""<original code
in multiple
lines>"""

which actually converts the code to a not accessible multiline string.
However, triple quoting is not an official means for multiline comments.
What you are seeing in your second example is implicit string
concatenation (which works regardless of the type of the quotes) -
adjacent string literals in the code are joined automatically:
>>> "abc" 'def' """ghi""" '''jkl'''
'abcdefghijkl'
>>>

hth,
  vbr

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how does not work nested comment in python? vnkumbhani@gmail.com - 2013-09-03 23:13 -0700
  Re: how does not work nested comment in python? Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-09-04 09:55 +0200
  Re: how does not work nested comment in python? Dave Angel <davea@davea.name> - 2013-09-04 12:08 +0000

csiph-web