filmov
tv
Create multiline comments in Python?

Показать описание
PLEASE COMMENT, SUBSCRIBE, AND SHARE!!!
Way to create multiline comments in Python?
Inspired by:
Best Answer Section:
"
up vote
847
down vote
accepted
You can use triple-quoted strings. When they're not a docstring (first thing in a class/function/module), they are ignored.
'''
This is a multiline
comment.
'''
Guido van Rossum (creator of Python) tweeted this as a "pro tip".
However, Python's style guide, PEP8, favors using consecutive single-line comments, and this is also what you'll find in many projects. Editors usually have a shortcut to do this easily.
shareimprove this answer
edited Jun 30 at 14:27
Martijn Pieters♦
511k7513581508
answered Oct 8 '11 at 12:58
Petr Viktorin
26.4k24660
7
16
@unutbu, if it was the only thing in the file, it was a docstring. Put some code before it and it'll disappear from the pyc. I edited the answer and put „module“ to the list of things that have docstrings. – Petr Viktorin Oct 8 '11 at 13:21
18
I don't like multiline string as comments. Syntax highlighting marks them as strings, not as comments. I like to use a decent editor that automatically deals with commenting out regions and wrapping multiline comments while I type. Of course, it's a matter of taste. – Sven Marnach Oct 8 '11 at 13:31
37
As a convention I find it helpful to use """ for docstrings and ''' for block comments. In this manner you can wrap ''' around your usual docstrings without conflict. – Roshambo Dec 18 '12 at 20:03
3
While you can use multi-line strings as multi-line comments, I'm surprised that none of these answers refer to the PEP 8 subsection that specifically recommends constructing multi-line comments from consecutive single-line comments, with blank # lines to distinguish paragraphs. – Air May 21 '14 at 19:32
"
Way to create multiline comments in Python?
Inspired by:
Best Answer Section:
"
up vote
847
down vote
accepted
You can use triple-quoted strings. When they're not a docstring (first thing in a class/function/module), they are ignored.
'''
This is a multiline
comment.
'''
Guido van Rossum (creator of Python) tweeted this as a "pro tip".
However, Python's style guide, PEP8, favors using consecutive single-line comments, and this is also what you'll find in many projects. Editors usually have a shortcut to do this easily.
shareimprove this answer
edited Jun 30 at 14:27
Martijn Pieters♦
511k7513581508
answered Oct 8 '11 at 12:58
Petr Viktorin
26.4k24660
7
16
@unutbu, if it was the only thing in the file, it was a docstring. Put some code before it and it'll disappear from the pyc. I edited the answer and put „module“ to the list of things that have docstrings. – Petr Viktorin Oct 8 '11 at 13:21
18
I don't like multiline string as comments. Syntax highlighting marks them as strings, not as comments. I like to use a decent editor that automatically deals with commenting out regions and wrapping multiline comments while I type. Of course, it's a matter of taste. – Sven Marnach Oct 8 '11 at 13:31
37
As a convention I find it helpful to use """ for docstrings and ''' for block comments. In this manner you can wrap ''' around your usual docstrings without conflict. – Roshambo Dec 18 '12 at 20:03
3
While you can use multi-line strings as multi-line comments, I'm surprised that none of these answers refer to the PEP 8 subsection that specifically recommends constructing multi-line comments from consecutive single-line comments, with blank # lines to distinguish paragraphs. – Air May 21 '14 at 19:32
"