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


Groups > comp.lang.python > #53599 > unrolled thread

how does not work nested comment in python?

Started byvnkumbhani@gmail.com
First post2013-09-03 23:13 -0700
Last post2013-09-04 12:08 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  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

#53599 — how does not work nested comment in python?

Fromvnkumbhani@gmail.com
Date2013-09-03 23:13 -0700
Subjecthow does not work nested comment in python?
Message-ID<551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com>
example: 
 
print "hello" # print comment +"world"    => single line comment
print "hello" '''print comment''' +"world"   => multiple line comment

[toc] | [next] | [standalone]


#53606

FromVlastimil Brom <vlastimil.brom@gmail.com>
Date2013-09-04 09:55 +0200
Message-ID<mailman.32.1378281321.5461.python-list@python.org>
In reply to#53599
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

[toc] | [prev] | [next] | [standalone]


#53620

FromDave Angel <davea@davea.name>
Date2013-09-04 12:08 +0000
Message-ID<mailman.39.1378296555.5461.python-list@python.org>
In reply to#53599
On 4/9/2013 02:13, vnkumbhani@gmail.com wrote:

> example: 
>  
> print "hello" # print comment +"world"    => single line comment

>>> print "hello" # print comment +"world"    => single line comment
hello


> print "hello" '''print comment''' +"world"   => multiple line comment

>>> print "hello" '''print comment''' +"world"   => multiple line comment
  File "<stdin>", line 1
    print "hello" '''print comment''' +"world"   => multiple line comment
                                             ^
SyntaxError: invalid syntax
>>> print "hello" '''print comment''' +"world"
helloprint commentworld

What is your question?  The first line has a comment on it, the second
one does not.

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web