Important Python Concept

Comments in Python

Comments are basically lines that give us a brief description of the code written without being noticed by the compiler. They are an amazing way to explain what each part of the code does. It makes the code much easier to comprehend both for the programmer and his audience.

 

Let’s create a Comment in Python

 

A comment begins with a hashtag and white space character thereafter.

Example
 
#This is how you can easily comment.
 

Types of Comments

 

Comments can basically be submerged into the following types:
1. Single Line Comments
2. Multiline Line Comments

 
Single Line Comments

 

The Single Line Comment is the most basic type of comment. Like all comments, it starts with a hashtag and is further followed by the explanation written, being ignored by the compiler.

It is used for some quick explanation of the code.

 

a = 6
print(a)
# a is a variable that has been assigned the value of 6.

 

OUTPUT:
6
 
Multi Line Comments

 

A comment spread over multiple lines is called a multi line comment. To understand it better, consider the following example:

 

"""
The program shown below prints hi
It is an awesome feature of python
I'm in love with python
"""
print("Hi")

 

OUTPUT:
Hi
Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?