COMMENTS IN PYTHON

Python Comments

Now, we are going to have a look at comments in Python. If you are already familiar with some other programming language like C/C++ or Java, you might be already familiar with this term comment. But still, if you are not familiar, do not worry, since we are going to look at these things from scratch here.

We would look into why comments are used in the program and how we can use them in our programs.

Here is an insight into what are we going to cover in this section –

  • single line comments in python
  • multiline comments (using multiple single line comments, or multiline string)

So, the comments are nothing but some description of our block of code or our program. Basically, it is used to describe what we are doing. For example, let’s say that we are writing some function in our program, which is just a block of code, and through the comments, we are describing what this function does.

The thing is that the comments are completely ignored by the interpreter. So, whatever you comment, is going to be straightaway ignored. This also tells us that if we comment on some line of code in python, it is also going to be ignored, and then it won’t execute.

So, in situations, when we want some line of code to be not executed, but you want it in the program, you can simply comment it out, and it would be ignored, just like any other comment. So, this can be said as another use of comments.

So, we can say that the comments are there in our program, to describe our program or some block of code, or in short, we can say that comments just make our program more readable and understandable. Also, comments can help us in preventing the execution of some code, without removing it from the program.

So, when we have understood the importance of comments, Let’s now have a look at how we can comment in python.