Skip main navigation


How to use comments in Python and why they are useful.

As your programs are getting more complex, you may find it more difficult to keep track of what each part of your code does.

A way to help you remember what different parts of your code do is to include comments within the code.

Comments are text within code that are notes for the programmer or another person using the code. The computer ignores all comments when it runs the code.

In Python, you create a comment by putting a hash character # before some text. For example:

# this is a comment

You can add comments anywhere within your program.

Typically, comments are reminders about what particular lines or sections of code do. For new learners such as yourself, comments are also a useful tool for explaining what programs do step by step.

# ask the user to enter their name
name = input("what is your name?")

# print a message including the name
print("Hello " + name)

In Python, you can make a comment span multiple lines by putting a # at the start of each line.

# comments can span
# multiple lines
# if a hash character is placed
# at the start of each line

Add some comments to your bot program to describe what it does.

This article is from the free online

Programming 101: An Introduction to Python for Educators

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education