Comments in Python

Commenting in Python Code

Comments in Python Code means removing some part of code from the operation without deleting it from the text area. Comments are used in every programming language to write some none coding information about what operation is performed in the below or a specific line. Let’s learn more on Comment in Python programming.

To learn more about Python programming click on the button below

What does the comment do in Python?

Comments are used in every programming language to remove the operability of the line of code. We can comment single line and even multiple lines in code. We use some different symbols to eliminate the operability of the piece of code. Different methods to comment on the code are:-

  1. #:- Used to comment on the single line of code in Python.
  2. ”’…..”’:- Used to comment on multiple lines in Python
  3. “””…..”””:- Also Used to comment on multiple lines

We can use any of the type mentioned above to comment on the python code. Not only the python code Comments are also used by programmers to make their codes readable. Commenting the code gives a clear explanation about what operation programmer want to perform in the coming line.

Using Comment lines can help you to save more time while implementing operations. For example, Initially, if we performed an operation to a program like sorting an array in ascending order. But now you want to run the same code with a sorted array in descending order. So you can comment the code for the time of not using it and again remove the comment when you want to run it in your programme.

Advantages of using Comments in Code

Some advantages of usding comments in your code are as follows:

  • Makes the code readable
  • Make your code easy to understand
  • Saperate your functions and methords in a better way

Code for Comments in Python

#initialize a string      
arr = 'PrepInsta'
#using step argument without start and stop
#this will print the string as it is                      #commented the lines using single comment format
'''This will print the string in reverse order
starting from the index 2 to ending point 6'''           #Commented the lines using multiple line comment format
ar = arr[2:7]

"""This will print the string elements with even index
Starting from 2 to 7"""                                   #Commented the lines using multiple line comment format