Table of Contents
Python Comments
- Python comments can be used to explain source code.
- Python comments can be used to make the source code more readable and easy to understand.
- Python comments can be used to prevent execution when testing code.
- Comments can be placed at the end of a line, and Python will ignore the rest of the line.
Types of python comment
There are two types of comments used in python:
- Single line Comment
- Multiline Comment
Single line Comment
- A comment which gives only one line is called a single-line comment.
- It is represented by the # (hash) symbol.
Example 1
#This is a comment
print("This is NIELITBHU!")
Example 2
print("This is NIELITBHU!")#This is a comment
Multi Line Comments
- A comment which gives more than one line is called a multi-line comment.
- It is represented by the ”’ ”’ (Single triple quote open and close) symbol.
- It is also represented by the “”” “”” (Double triple quote open and close) symbol.
Example 1
'''
This is a comment
written in
more than just one line
'''
print("hii this is Ashish here!")
Example 2
"""
This is a comment
written in
more than one line
"""
print("hii this is Ashish here!")