In this lesson, we’ll make comments about commenting using the hashtag and quotes. Coding with comments will help you understand your code quickly.

Previous Lesson: Lesson 7: Operators and Delimiters in Python

In this lesson, we’ll make comments about commenting in Python using the octothorpe or hashtag (#) and quotes (””” and “”””””). When you’re reading your code with comments on many lines, you’ll know what that line of code does.

Let’s just open our ex2.py file. Hopefully, you still have it with you. We’ll do something incredible in it and you’ll see how we’ll be commenting in Python using the hashtag and quotes. We’ll make sure that our code still runs fine:

Very good.

Commenting Using the Octothorpe or Hashtag(#)

Note:#‘ is called an octothorpe. And it’s also known as a hashtag.

Now, make your ex2.py look exactly like mine:

Now, when we run this, we should not see comments; they should not get printed. That’s what commenting is–you just comment. On Mac, this is what my Terminal spat out:

Nice and neat. If you have an error, double-check. Remember: Read your code from bottom to top; read every character aloud. Especially this time, when you encounter the #, say “octothorpe!” so that you’ll remember this symbol.

Commenting Using Quotes

But what if we want to write a lot of comments, that our project turns into a commenting project instead of a coding project? If you really want to write comments on that many lines, you can use three pairs of double-quotes or three pairs of single-quotes. Like what we did on Line 29 down to Line 33:

Why do we use this anyway? That’s because if a time comes when we’re not sure whether to keep something or if we would be using it for later. So to prevent that chunk of code from being completely gone out from history, like that on Line 30 down to Line 32, we can do that. Or, we can also do three pairs of double-quotes:

The outcome should be the same. However, if it’s not the same, you may have missed something or forgot something. Double check and then run it until it still looks like this:

This image has an empty alt attribute; its file name is image-133.png

Comments are important so that when you read your code or when you check it, you may have comments where you can say what that piece of line in your code does and everything. We’re going to use these very often.

Talking about comments, leave a comment down on the Comments section and tell me everything that you want to tell me.

Next Lesson: Lesson 9: Functions in Python and Their Significance

This article was written by Zeddrix Fabian

Zeddrix Fabian became one of Jehovah’s Witnesses on February 21, 2016, and started regular pioneering last March 2020. He wants to volunteer at Bethel⁠—that is his goal. After going to both private and public school for 10 years (Grade 1 to 8 in private; Grade 9 and 10 in public school), their family started trying homeschooling when he leveled up to Grade 11 last 2019. (Continue reading on ABOUT ZEDD menu)

3 thoughts on “Lesson 8. Commenting In Python”

Leave a Reply

Your email address will not be published. Required fields are marked *