Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 2.2Comments in Python

Commenting is a very useful way of reminding future programmers or the original programmer when they haven't programmed on the same project for a long time what a section of code does. Therefore, it is recommend to comment code while working on it.

Most commercially developed applications have been commented because a wide array of people will work on them.

Commenting code in Python

There are two methods of commenting in Python. The first is the single line comment. This comment will take just that line of code out of the interpreted program. This is achieved using the # hash sign in Python:

Python
#This is a comment
    

The second option is the block comment (also known as a multi line comment). This will remove multiple lines of text from the interpreted program. This is achieved using the ''' syntax:

Python
'''This is a comment
This is also a comment
'''
    
  1. Add a single-line comment containing your name.
  2. Add a single-line comment describing your favourite hobby.
  3. Create a multi-line comment containing three facts about yourself.
  4. Try replacing the text in the examples with your own comments.

Why do you think comments are useful to programmers working on large projects?

Extension challenge: Write a short multi-line comment describing what you have learned about comments in Python.

Feedback 👍
Comments are sent via email to me.