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 they are not printed.
#This is a comment!
​
print("Welcome to Python!")
​
#The code above prints a nice greeting
=
Welcome to Python!
Programmers use comments to explain to other people (and themselves) what different sections of code do. With massive programs, comments are vital; otherwise, it would be too confusing, especially after returning from a few weeks or months on a different project.
If you are creating a Python project for school (or A-Level Computer Science coursework), you will need comments to explain your code and prove you have written it yourself.
Comments over Multiple Lines
Have a lot to say in one comment? Use three apostrophes ( ”’ ) at the start and three more at the end of your comment like below:
'''This is a comment that
I have spread out over more
than one line'''
print("Hello! How are you?")
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.
Commenting Task 1 (Day of the Week & Weather)
On line 1 write a single-line comment (use #) to state that your program will print the day of the week.
On line 2 print the current day of the week.
On lines 3, 4 and 5 write a multi-line comment (use ''') about the weather today.
​
Remember comments won't be printed so only the day of the week should be output.
Example solution:
Wednesday