Archangel Macsika Sikademy Image
Archangel Macsika

Learn How to Use Comments in Python Programming

Tutorial 6 of 10 | 3 minutes read
Learn How to Use Comments in Python Programming - Sikademy

Comments in Python

In programming, comments are statements ignored by the interpreter or compiler when the program runs. They are used to explain a specific block of codes or a line of code.

Comments can be used to improve the readability and overall understanding of a program.

It can also be used to prevent a specific block of code or line of code from executing.

How to Create Comments in Python Programming

Comments can be short (single-line comment) or long (multi-line comments).

Single-Line Comments

In python programming, short comments begin with the # symbol. This means that python will not execute any line that begins with it.

You can place a comment at the end of each line of code.

You can also comment on one or more codes. This will prevent the code from executing.

The output of the above programs will be:

Hello, Archangel!

Multi-Line Comments

Comments do not always have to be in a single line. Sometimes, you may want to write a paragraph describing a block of codes. This is called a multi-line comment.

There is no official syntax for a multi-line comment in Python programming. But, there are ways around it.

One way to implement multi-line comments in Python programming is the use of multiple short comments by inserting a # for each line:

Another way to implement multi-line comments in Python programming is to use a multiline string.

In the previous tutorial, we showed you how to use multiline strings to assign a large string (paragraph) to a single variable.

To use multiline strings as multi-line comments, do not assign it to a variable:

You can also use single quotes:

The output of the above programs will be:

Hello, Archangel!

Wrap Off

Comments are fundamental when developing large programs individually or in teams. A rule of thumb is to ensure all comments are clear, precise, and comprehensive. You can write comments in languages other than English.

If you run into errors or unable to complete this tutorial, feel free to contact us anytime, and we will instantly resolve it. You can also request clarification, download this tutorial as a pdf, or report bugs using the buttons below.

Tutorial Exercise

Write a program to print "Hello, Macsika" and a long comment describing the function of the program using the two methods of multi-line comments we discussed.


Enjoy this Tutorial? Please don't forget to share.