Sabuj Hassan
Sabuj Hassan

Reputation: 39365

Python comment multiple line

Is there any way to comment multiple lines at Python(Not using IDE's CTRL+... command)? I mean the way of C/C++/Java does it /** ... */

I have seen some developers have been using below example for this purpose.

'''
here goes the comment!
more comments..
'''

But this seemed to me the Perl's begin/cut like commenting, which was designed for one purpose, but people can use that as milti line commenting.

=begin
here goes the comment
=cut

If there is no other way, then Will it be safe if I use triple quotes for the commenting? Does it have any pitfalls?

Upvotes: 1

Views: 357

Answers (2)

WLin
WLin

Reputation: 1454

Using triple quotes is the standard for multi-line comments in Python. This technique has also been approved by Guido van Rossum who is the creator of Python.

You might also want to take a look at the PEP8 Style Guide for more widely accepted practices in Python.

Finally, make sure that you are using a good IDE (I use PyDev/Eclipse) for that syntax highlighting among things. That alone will greatly help reduce the chance of improper usage of multi-line comments.

Upvotes: 1

MattDMo
MattDMo

Reputation: 102862

Many IDEs/text editors allow for highlighting multiple lines and hitting a key sequence to comment them all out with #, so you don't need to do each line individually. While triple-quoted strings are used as docstrings when formatted and placed in certain ways, many developers also use them for large comments, but they have to begin and end on lines that don't contain any other code.

To each his own, I suppose...

Upvotes: 1

Related Questions