What are some common uses for multi-line comments?


What are multi-line comments usually used for?


Multi-line comments are great for commenting out blocks of code. You may want to run your program without certain blocks of code when you’re debugging or testing new features, and writing a # on every line can be a pain!

You’ll also see, depending on the style choice of the programmer, documentation written in multi-line comments, rather than a large block of single-line comments.


Technically speaking Python does not have multi-line comments at all. The use of triple quotes (single or double) produces what is actually called a docstring. Strictly speaking a comment is not included in the compilation and run of a program. A docstring (controversially) is executed in Python. It is essentially the same as typing a single 1 or True on a line. This is a statement that is evaluated albeit very quickly.

Docstrings are used to comment out large amounts of code to turn it off, but they are also very importantly used in a specific way to provide pydoc documentation about the code. It is worth learning about this documentation convention early so you can begin to document your code in an easy way that is compatible with the suite of documentation tools.


You’re right, python doesn’t have a true multi-line comments. Where its # at every line.

After highlighting the lines of code we want to comment, we can use the cntl + / shortcut for Window users or command ⌘ + / for Mac users.

I completely forgot about it until I was reviewing while loops in a python lesson. :sweat_smile:

Is there a shortcut for uncommenting multiple lines?
Edit: Nevermind, I figured out that it’s the same

1 Like