How do I create multiline comments in Python?
In Python, you can create a multiline comment using triple quotes (either single or double) at the beginning and end of the comment.
In Python, you can simulate a multiline comment using triple quotes (either single or double) at the beginning and end of the text. Technically, these are string literals, not true comments. If left unassigned, Python ignores them at runtime. Here's an example:
Simulate multiline comments in Python using three double-quotations
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
You can also use triple single quotes (''') to simulate a multiline comment, like this:
Simulate multiline comments in Python using three single-quotations
You can place these string literals before or after a statement or group of statements, or on their own line. While often used to document code or add notes for other developers, remember they are technically string literals. For formal documentation of functions or classes, Python uses docstrings (triple-quoted strings placed immediately after a definition).
For actual comments, use single line comments with #, which will comment out the rest of the line.
Create single line comments in Python using the hash sign