Comments in Python 3

Comments in Python 3

Comments in Python 3 are a little bit different from other programming languages such as PHP etc. Python comments start with the hash(#) symbol and the block or a line of code started by # is ignored in python. Comments are also used to stop the execution of a piece of code. Also, We can put the comments at the beginning of any piece of code to describe the code.

Also read, Python Indentation and Errors with Example

Below are the examples of comments in Python 3

Single line comment:- If we want to comment on a single line of code or block then we can do it as shown below

# This is a single line comment

Multiline Comments:- There is no symbol to comment multiline in python. Instead, we have to use the hash (#) symbol for each line as shown below

#This is the first comment

#This is a second comment

#This is a third comment

Also, there is another way, we can comment on multiple lines of code in Python by using triple quotes. We can put the required lines inside the triple quotes because python ignores the string values that are not assigned to a variable. We can do it as shown below

"""This is the first line,

this is the second line,

this is the third line"""

You can download the latest version of Python3 from here

Conclusion:- I hope this will help you to understand the concept of python comments. If there is any doubt then please leave a comment below

Leave a Comment