Comment (Python)

This page covers Comment in Python. For a language-agnostic introduction, see Comment.

A comment in Python is text the interpreter ignores. Python has one comment syntax: the single-line comment.

Single-line comment#

A single-line comment starts with # and continues to the end of the line.

# Everything on this line is a comment.
print("Hello, World!")

You can also write it inline, to the right of code:

print("Hello, World!")  # Everything to the right is a comment.

Multi-line comments#

Python has no dedicated block comment syntax. To comment across multiple lines, write a # at the start of each line:

# This is a comment
# that spans multiple
# lines.
print("Hello, World!")

Common Mistakes#

Using // instead of # // is the single-line comment syntax in C# and JavaScript. In Python, comments always start with #.

Using string literals as block comments You may see triple-quoted strings ("""...""") used as multi-line comments. This works in practice because Python evaluates the string and immediately discards it — but it is not a comment. It’s an expression with no effect. Use # on each line for real comments.

Putting # inside a string A # inside a string literal is not a comment — it’s part of the string. Only a # that appears outside of quotes starts a comment.

Resources#