Comments in Python
In Python, comments are used to include explanatory notes or annotations in our code. Python supports two types of comments:
1. Single-Line Comments Use the # 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")