Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53599 > unrolled thread
| Started by | vnkumbhani@gmail.com |
|---|---|
| First post | 2013-09-03 23:13 -0700 |
| Last post | 2013-09-04 12:08 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | vnkumbhani@gmail.com |
|---|---|
| Date | 2013-09-03 23:13 -0700 |
| Subject | how 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]
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
|---|---|
| Date | 2013-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]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-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