0% found this document useful (0 votes)
3 views3 pages

Understanding Python Comments

Comments in Python are non-executable statements that enhance code readability and understanding. There are two types of comments: single-line comments, which use the # symbol, and multi-line comments, which can be created using multiple # symbols or triple quotes. The interpreter ignores comments, making them useful for explanations without affecting program execution.

Uploaded by

anandthi1219
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Understanding Python Comments

Comments in Python are non-executable statements that enhance code readability and understanding. There are two types of comments: single-line comments, which use the # symbol, and multi-line comments, which can be created using multiple # symbols or triple quotes. The interpreter ignores comments, making them useful for explanations without affecting program execution.

Uploaded by

anandthi1219
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python COMMENTS

Comments are the non-executable statements in a program. It is just added to describe the
statements in the program code. Comments make the program easily readable and understandable
by the programmer as well as other users who are seeing the code. The interpreter simply ignores
the comments. Comments can be used to explain Python code. Comments can be used to make the
code more readable.
Types of Comments in Python
In Python, there are two types of comments:
 single-line comment
 multi-line comment
Single-line comments
A single-line comment starts and ends in the same line. We use the # symbol to write
a single-line comment.
Example:
# create a variable
name = 'Eric
Cartman'

# print the
value
print(name)
Output
Eric Cartman
Here, we have created two single-line comments:
# create a
variable # print
the value
We can also use the single-line comment along with the code.
name = 'Eric Cartman' # name is a string
Here, code before # are executed and code after # are ignored by the interpreter.
Multi-line comments
Python doesn't offer a separate way to write multiline comments. However, there is other
ways to get around this issue.

We can use # at the beginning of each line of comment on multiple


lines. For example,
# This is a long
comment # and it
extends
# to multiple lines
Here, each line is treated as a single comment, and all of them are

ignored. Another way of doing this is to use triple quotes, either ''' or """.

These triple quotes are generally used for multi-line strings. But if we do not assign it to any
variable or function, we can use it as a [Link] interpreter ignores the string that is not
assigned to any variable or function.

Let's see an example,


''' This is also a
perfect example of
multi-line comments
'''

You might also like