Comments
Published May 3, 2021Updated Oct 7, 2024
Contribute to Docs
A comment is a piece of text within a program that is not executed. It is used to provide additional information or context to help understand the code. Python uses the #
character to start a comment, which extends to the end of the line.
Single-line Comments
In Python, the #
character is used to start a comment. The comment continues after the #
until the end of the line.
# Comment on a single linename = "Pied Piper" # Comment after code
Multi-line Comments
Python does not have a specific syntax for multi-line comments, unlike some other languages. Instead, multiple #
characters can be used:
# This is a comment written over# more than one lineprint("Hello, World!")
Alternatively, multi-line strings (with triple quotes """
) can also be used as de facto comments. These are ignored by Python if not assigned to a variable:
"""This is a string written overmore than one line"""print("Hello, World!")
Codebyte Example
Run the following codebyte to understand how comments work in Python:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.