Comments in Python

In Python, comments are used to include explanatory notes or annotations in our code. Comments are ignored by the python interpreter at the time of execution of the program.

Python supports two types of comments:

1. Single-Line Comments Use the # hash symbol at the beginning of a line to create a single-line comment.

Example:

Python

# This is a single-line comment
print("Hello, World!")  # This comment explains the print statement 

2. Multi-Line Comments Python doesn't have a specific syntax for multi-line comments, but we can use triple quotes (''' or """) for the purpose.

Example:

Python

"""
This is a multi-line comment.
It can span multiple lines.
"""
print("Multi-line comments example") 

Alternatively, you can use multiple single-line comments:

Python

# This is a multi-line comment
# written using single-line comments.
print("Another way to write multi-line comments") 

Note: Triple quotes are technically used for docstrings (documentation strings), but they're often repurposed for multi-line comments in Python. However, docstrings are usually meant to document modules, classes, or functions.