Python 1b - Commenting

Writing Comments

To annotate your work, you can write a comment using the # symbol. Comments are ignored when you run the program and not printed.

Programmers use comments to explain to other people (and themselves) what different sections actually do. With huge programs comments are vital otherwise it would be too confusing. If you are creating Computer Science coursework, you will need comments to explain you understand and have written your own code.

Comments over Multiple Lines

Have a lot to say in one comment? Use three apostrophes (”’) at the start and three more at the end like below:

Top Tip: Use multi-line comments when testing a program to ‘blank out’ sections that you know work fine and only focus on one part at a time.

Practice Task

1. On line 1 write a single-line comment to state that your program will print the day of the week.

2. On line 2 print the current day of the week.

3. On lines 3, 4 and 5 write a multi-line comment about the weather today.

Example solution:

© CSNewbs 2019