Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What are comment types?

Muhammad Hameed

Comments are brief descriptions of the logic and workings of the written code. They are used to enhance code readability.

Generally, two types of comments exist:

  • single-line comments
  • multi-line comments
Comment types

For single-line comments, approximately 70 to 72 characters are recommended. Such comments are generally used before or in front of a statement to explain only that one statement.

A single-line comment in Python starts with #. The following is an example of a single-line comment:

# This is a single-line comment
print("Example of a single-line comment in Python")
Single-line comment in Python

Multi-line comments generally tend to explain a task and are more descriptive.

In Python, multi-line comments start and end with '''. The following is an example of a multi-line comment:

This is an example of a multi-line comment.
Multi-line comments are generally descriptive
in nature and tend to explain a block of code.
print("Example of a multi-line comment in Python")
Multi-line comment in Python

The code below demonstrates the use of single and multi-line comments in Python:

"""Program to print the multiplication table of 5
For instance 5 * 1 = 5
for i in range (1,11): #The loop runs 10 times
  print('5 * ',i,' = ',5*i)# i iteratively increases by 1 everytime



View all Courses

Keep Exploring