Comments are non executable statements. They are use for understanding and describing the purpose of code.
Below are two the types of comments in python
- Single line comment
- Multiline comment
Single line comment
Single line comment start with (#) hash symbol. For example in the below code we have use # symbol followed by some description. Characters after # is treated as comment.
#Variable store some value
lan = 'Python'
In the above code entire line after hash # is treated as comment and would be not executed by Python compiler.
a = 10 # Variable a storing value 10 b = 20 #Variable b storing value 20 c = a+b #Addition of a and b is assigned to variable c
In above three lines, statements after # is considered as comment.
Multiline comments
We can use single line comment to create multiline comment but that would be tedious job. Below is the example
#This is the first line comment #This is the second line comment #This is the third line comment
Instead of using # at every line to describe comments, we can use multiline comments enclosing within single (”’…comments..”’) or double triple quotes(“””..comments…”””)
Below is the example of multiline comments
Enclosing comments inside single triple quotes.
''' This is the first line comment This is the second line comment This is the third line comment'''
Enclosing comments inside double triple quotes.
"""This is the first line comment This is the second line comment This is the third line comment"""