If you want readable “paragraph” explanations in code, you still use the same # mechanism on every line. This page answers whether Python has a dedicated multiline comment, shows the recommended pattern, contrasts triple quotes and docstrings, lists editor shortcuts, and ends with pitfalls and a small lookup table.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic; Ubuntu 25.04.
Does Python support multiline comments?
# This is a multiline comment.
# Each line starts with #.
# Python does not have a separate multiline comment syntax.No. There is no second syntax like /* ... */ in C, Java, or JavaScript—only # through end-of-line is a comment. To “comment a paragraph,” repeat # at the start of each line. Prefix # plus a space for readability (PEP 8), and align # with the code block you describe so the scope is obvious.
# Compute moving average over window k.
# Caller must pass k >= 1; empty series returns [].
def moving_average(values, k):
...# lines add no runtime objects, work in tight layouts, and match what linters and reviewers expect. In the language itself there is only this one style of comment; what changes is how you produce many # lines—by typing them or by letting the editor insert them for a selection (see below). That is convenience, not a second comment syntax.
Triple quotes and docstrings
Triple quotes always define a string literal, not a lexer-level comment. A module-level """...""" before other code still creates a string object that is then discarded if unused—it is easy to misread and may annoy style checkers.
"""
This looks like a comment block but it is a string value.
Python creates the object, then throws it away if it is not assigned.
"""
x = 1If the first statement in a module, class, or function is a string literal, Python stores it as __doc__ (a docstring). That is for API documentation and help(), not for ordinary narration in the middle of logic.
class Car:
"""This class contains all the info about car."""
print(Car.__doc__.strip())Running this prints one line: the sentence inside the triple quotes. Avoid triple-quoted “comments” mid-function, as trailing notes, or to disable code; use # lines or editor folding, and use line-comment toggles to turn real code off temporarily.
A comment starts with # and runs to the newline; the interpreter never executes that text. A docstring is a string (usually triple-quoted) that appears as the first statement in a module, class, or function and is stored in __doc__.
| Aspect | Comment (#) |
Docstring (""" / ''') |
|---|---|---|
| Purpose | Explain code to readers | Document public API of module/class/function |
| Syntax | # to end of line |
String as first statement in suite |
| Runtime | Stripped by lexer | Stored in __doc__ (first string only) |
| Mid-function notes | Use # on each line |
Do not use bare triple strings as “comments” |
For broader learning context, see beginner tips for learning Python. When a comment sits beside a long expression, line continuation rules explain where you may break lines; for multi-line string literals (not comments), see multi-line strings.
Editors, block style, and inline comments
For multiline remarks, select the lines you want, then run the editor’s line-comment action. It prefixes # on each selected line; run the same command again to remove those # characters. Typical bindings:
- VS Code:
Ctrl+/on Windows and Linux,Cmd+/on macOS (Toggle Line Comment). - PyCharm and other JetBrains IDEs:
Ctrl+/on Windows and Linux,Cmd+/on macOS (Comment with Line Comment). - JupyterLab or the classic notebook: with the cursor in a cell, select lines and use
Ctrl+/orCmd+/in the cell editor; behavior matches most code editors, but keymaps can differ if you customized them. - Other editors: search the command palette for “line comment” or “toggle comment” and bind the action that inserts
#per line for Python—avoid language modes that insert/* */, which are not valid in Python.
A block comment in Python style is several consecutive # lines placed before the code they describe, at the same indent as that code:
# Validate bounds before indexing.
# Raises ValueError if out of range.
if not 0 <= i < len(items):
raise ValueError("index out of range")An inline comment sits after a statement on the same line; everything after # is the comment. Keep these short; put longer reasoning on full # lines above.
limit = 100 # default page sizeCommon mistakes and quick reference
- Treating
"""..."""in the middle of a function as “free” commentary—it still builds a string. - Mis-indenting a triple-quoted string so it does not attach where you think; you can get syntax errors or accidental string concatenation.
- Forgetting that only the first string in a function becomes the docstring; later strings are ordinary expressions.
- Using a VS Code “block comment” action meant for other languages that inserts
/* */—that is not valid Python.
| Need | What to do |
|---|---|
| Multiline explanation | Several # lines |
| Quick disable code | Editor toggles # on each selected line |
| API documentation | Docstring as first statement in module/class/def |
| Not a comment | Triple-quoted string not in docstring position |
Summary
Python has no /* */-style multiline comment: use # on each line, optionally via your editor’s toggle. Triple quotes always define strings; when they are the first statement of a module, class, or function they become docstrings in __doc__. Reserve docstrings for real API documentation and use # for ordinary multiline remarks so behavior stays clear to humans and tools.

