Want to keep learning?

This content is taken from the Raspberry Pi Foundation & National Centre for Computing Education's online course, Programming 101: An Introduction to Python for Educators. Join the course to learn more.


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.

Share this article:

This article is from the free online course:

Programming 101: An Introduction to Python for Educators

Raspberry Pi Foundation