All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Comment Multiple Lines In Python

Last Updated : Mar 11, 2024

How To Comment Multiple Lines In Python

In this tutorial we will show you the solution of how to comment multiple lines in python, commenting is a way to write something, describe something or express something about a particular subject.

However, inside a program, we don’t want the compiler or interpreter to compile or interpret those lines.

In fact we need to mute the functionality of those statements. They are only for the convenience of human users.

Also for program testing or debugging purposes, we need to comment out (mute) some statements to see upto which statement our program is working correctly.

Thus, sometime or the other, there is a genuine need to comment multiple lines of code.

We will show You how to do it in Python.

Step By Step Guide On How To Comment Multiple Lines In Python :-

a = 5 This is a
b = 6 This is b
c = 7 This is c

Just write # beside a statement You want to comment and it will be commented.

a = 5 #This is a
#b = 6 This is b
"""c = 7 This is c"""
  1. We will use VS Code for this demonstration. Any IDE such as Spyder, Atom, Sublime can also be used.
  2. This is an elementary program which declares and assigns values 5, 6 and 7 to three variables a, b and c.
  3. Beside a, we wrote the description and similarly beside b and c.
  4. It’s a no brainer that we wrote the description only for our convenience and not for the interpreter to run those statements. So we need a way to “hide” those descriptive statements from the interpreter so that they’re bypassed. The way is to comment.
  5. If we write # before the start of any statement, the whole statement gets commented. So before commenting, we should decide which part to comment.
  6. Another way to comment is to enclose a statement inside triple quotes (“””statement_here“””).
  7. Please note that this one works for an entire statement and not the later part of any statement. This method is useful to create docstrings, which are descriptive explanations attached with any module, function etc. Elaborations on it in the future!

Conclusion :-

I hope this tutorial on how to comment multiple lines in python helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪