Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Python have multiline comments?

OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,

"""Hello, I am a     multiline comment""" 

and

'''Hello, I am a     multiline comment''' 

But technically speaking these are strings, correct?

I've googled and read the Python style guide, but I was unable to find a technical answer to why there is no formal implementation of multiline, /* */ type of comments. I have no problem using triple quotes, but I am a little curious as to what led to this design decision.

like image 460
CoolGravatar Avatar asked Dec 29 '08 04:12

CoolGravatar


People also ask

Why does Python not have multiline comment?

The real workaround for making multi-line comments in Python is by using docstrings. If you use a docstring to comment out multiple line of code in Python, that block of code will be ignored, and only the lines outside the docstring will run.

Can you do multiline comment in Python?

Unlike other programming languages Python doesn't support multi-line comment blocks out of the box. The recommended way to comment out multiple lines of code in Python is to use consecutive # single-line comments.

How can you quote a multiline comment in Python?

if writing a text in a single line then use double quotes or single quotes in python. if writing a poem or songs or multi-line text then to use triple quotes(“”” or ”').


1 Answers

I doubt you'll get a better answer than, "Guido didn't feel the need for multi-line comments".

Guido has tweeted about this:

Python tip: You can use multi-line strings as multi-line comments. Unless used as docstrings, they generate no code! :-)

like image 74
Ned Batchelder Avatar answered Oct 10 '22 08:10

Ned Batchelder