Comments in the Python Programming Language
In this tutorial, we will learn how to comment in multiple lines and paragraphs in the python programming language.
Commenting a Paragraph in Python
Most people think the importance of comments is just to stop the compiler from executing the code and avoid running it. This is only one perspective. Say there are three main points to note to understand the absolute need for execution; they are
- The comments in Python or any programming language are to make the program written understandable.
- To explain the different libraries or built-in functions used more readable.
- As said earlier, the comment prevents the code written to prevent execution from being ignored.
To comment on a paragraph, we use triple quotes at the start of the program and at the end of the program too.
See the below code for reference:
Code
#commenting in Python
""""
This is a paragraph
written to demonstrate the use of
commenting multiple lines or a paragraph
"""
print('Hello World!')
Output
Hello World!
Comment Multiple Lines in Python
As demonstrated above, we will be using triple quotes at the start and also at the end of the code to tell the compiler to ignore whatever is written in it.
Similarly, to comment on single or multiple lines, instead of triple quotes, we can simply use a hash at the beginning of the statement to be ignored. We will be using these hash symbols at the front of each line that is to be made a comment.
See the below code for reference:
Code
#commenting in Python
#this is to demonstrate single line commenting
#compiler ignores statements or code written after hash symbol
print('Hello World!')
Output
Hello World!