Python Programming – Using Comments

You can learn about Introduction to Python Programming Programs with Outputs helped you to understand the language better.

Python Programming – Using Comments

Comments are entries in a computer program for the purpose of documentation or explanation. They should be written in such a way that even a begin¬ner can understand the logic of the program easily. Any text contained within comments is ignored by the Python interpreter. Every programming language has different ways to give comments in programs. Comments should be used intelligently to improve the quality and understandability of the program.

In Python, the line after # (hash) is called a comment. Use # to comment out a line of code or to add a short, one-line comment to your program. For example,
# Compute the average of the values
avg = sum / number
The above line here is a comment that explains what the statement that follows is supposed to do. The comment begins with the # symbol and continues until the end of that line. The interpreter will ignore the # symbol and the contents of the rest of the line. You may also append a short comment to the end of the statement:
x=5 # assign 5 to x
avg = sum / number # Compute the average per= (total*100) /500 # Compute percentage Here, an executable statement and the comment appear on the same line. The interpreter will read the assignment statement, but it will ignore the comment.
In Python, use a triple quote for multi-line com¬ments. For example,
This is
an example of
multi-line comment
print (“Hello World”)

  • Good programmers clarify their code by inserting remarks that explain the purpose of a section of code.

Leave a Reply

Your email address will not be published. Required fields are marked *