Comments are used to put some text into the Python code. This text can be used to explain something about the application or some method data etc. Python provides two types of comments named Single Line
and Multi-Line
.
Single Line Comment
#
is used to create a single-line comment. We will put #
to the start of the line and the whole line will be interpreted as a comment and there will be no command execution.
# This is a single line comment print("Hello Poftut.com") #This is another single line comment print("Hello Poftut.com") #This is a single line comment too
Multiline Comment
Python also provides the multiline string which is triple quotes in our code. We will put triple quotes in order to start the multiline comment and put triple quotes to end the multiline string.
""" This is the comment for multi line Comment """ print("Hello Poftut.com")
We can also use strings in multiline comments start and end lines by providing comments.
""" This is the start of the multiline comment This is the body of the multiline comment This is the end of the multiline comment""" print("Hello Poftut.com")
Multiple Single Line Comment
There is also an alternative way to create multiline comments in Python. We can use multiple single-line comments.
# This is a single line comment # This is another single line comment # This is comment which will look like multiline comment print("Hello Poftut.com")
Commenting Code
We can also comment on valid code. This will make the code just comment and the code line will not be executed. In this example, we will comment the print("Hello Poftut.com")
line and there will be no output.
# This is a comment # print("Hello Poftut.com") a = 5