What are some common uses for multi-line comments?


#1

Question

What are multi-line comments usually used for?

Answer

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.


FAQ: Learn Python - Python Syntax - Multi-line Strings
#2

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.