Comments in Python are lines of text that are written in the code but are not executed by the Python interpreter. These comments are used to provide information and explain what the code does. They are meant for human readers, such as other programmers or yourself, to better understand the code.
There are Two types of comments in python are given below.
- Single-line comments
- Multi-line comments
Single line comments in Python are brief explanations or clarifications that occupy only one line of code and are indicated by the hash symbol (#). They are used to make the code more readable and understandable, and are ignored by the Python interpreter.
Example:
print("Hello world")
print("Hello world")# this is a single line comment
# print("Hello world")
print("Hello world")
Multiline comments in Python are comments that span across multiple lines of code and are used to provide detailed explanations or documentation for functions, classes, or modules. They are indicated by a set of triple quotes (""") at the beginning and end of the comment block.
Example:
print("Hello world")