Erle Robotics Learning Python GitBook Free

Introducing comments

Single Line Comments

Comments make your program easier to understand. When you look back at your code or others want to collaborate with you, they can read your comments and easily figure out what your code does.

The # sign is for comments. A comment is a line of text that Python won't try to run as code. It's just for humans to read.

Practice 1

Write a comment on line 1. Make sure it starts with #. It can say anything you like. The result when running a comment on the interpeter must be the following one:

root@erlerobot:~# touch Comment.py
root@erlerobot:~# echo ' #This is a comment (readonly)' > Comment.py
root@erlerobot:~#
root@erlerobot:~#
root@erlerobot:~# python Comment.py
root@erlerobot:~#
Multi-Line Comments

The # sign will only comment out a single line. While you could write a multi-line comment, starting each line with #, that can be a pain.

Instead, for multi-line comments, you can include the whole block in a set of triple quotation marks:

"""This is a paragraph containing
readonly comments"""