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:

[email protected]:~# touch
[email protected]:~# echo ' #This is a comment (readonly)' >
[email protected]:~#
[email protected]:~#
[email protected]:~# python
[email protected]:~#
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"""