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.
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.
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.
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 ”').
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! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With