Comment is the part of the Python program which will not be executed or simply ignored by the interpreter or compiler where the program get running environment.
Comment is used to describe and document the code. In a industry level program may contain a thousands of lines codes. So, pointing out which part of the program does what is important. For that purse comments are used.
Types of comment in Python:
There are two types of comments in Python.
- Single line comment and
- Multi Lines comment
Single line comment:
For a single line comment, number or hash(#) is used. Lets see an example:
#This line prints a greeting message print(“Hello everyone! Good morning!”)
Here there will be no impact of #This line prints a greeting message in program’s output. This line will be ignored.
Multi lines comment:
Multi lines comment is for documenting or explaining the code in more detail. For making a multi lines comment, three quotations marks is used in the starting and ending of the commenting lines. Example:
""" This is a multi lines comments in Python. This commenting system is used for documenting the code """
We may think of making Multi lines comment using single comment pattern, like:
#This is a multi lines comments in Python. #This commenting system is used for documenting the code
But this is not a good practice. Triple quotations marks pattern is the best way of making multi lines comment in Python.