How To Comment Multiple Lines In Python
Last Updated : Jul 1, 2023
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"""
- We will use VS Code for this demonstration. Any IDE such as Spyder, Atom, Sublime can also be used.
- This is an elementary program which declares and assigns values 5, 6 and 7 to three variables a, b and c.
- Beside a, we wrote the description and similarly beside b and c.
- 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.
- If we write # before the start of any statement, the whole statement gets commented. So before commenting, we should decide which part to comment.
- Another way to comment is to enclose a statement inside triple quotes (“””statement_here“””).
- 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!
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.