How to put comments in the code Pro Preview

When we write code, it's crystal clear to us what it does, but this won't be the case in a few months when we might have to change it again.

This is why it's good practice to place comments in the code where we explain what different parts of the code do.

To access the full video please subscribe to


  • #1638
  • 27 Jul 2020

There are two ways to place comments in Python code.

Single line comments

A comment that takes up a single line can be written after a "#" character:

# Comment

If the comment is used to explain a singular command, it can be placed on the same line right after it:

ev3.speaker.play_file(SoundFile.BOING) # Plays the sound "BOING"

Multi-line comments

If we wish to use more than one line for a comment, we can place it in between a pair of three double quotes:


The first three double quotes mark the beginning of the comment. If the code does not have another three double quotes, then the program will treat the rest of the code as a comment and will not execute it.

Many programmers mark parts of their code as comments when they want to temporarily switch it of without deleting it.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Python with LEGO Mindstorms EV3 - Level 2
  • 39
  • 19:58
  • 93