How Do You Pass Notes to Others (or Your Dumber Self)?

On how to use comments in Python

In Python, if you want to say something that the computer doesn’t need to know but your fellow programmers do  – such as “If you change any characters in this line of code, the whole program goes kablooey” – then you need to stick in a pound sign (#) or put your comments into triple quotes. Try this in your Shell:

>>>print ("Hello, world!") #This line says hello

You should see Hello, world! without all the verbiage to the right of the pound sign. That message to the right of the sign is only for your self, or your fellow programmers. Now, try this (but in your Text Editor rather than the Python Shell):

print ("Hello, world!")
This is a verbose comment to you, the programmer. I wanted 
to mention that this line provides an existential salutation,
a signal of optimism to an oft-hostile universe via a medium 
that is also a message

Here’s how it would look in your Text Editor:

Go ahead and run it and you’ll see that the comment never shows up but “Hello, world!” does (except without the quotation marks).

Remember: that verbose comment needs to go below the first line. The triple quotations marks (outside the holy confines of the parentheses, that is) allows you to leave a multi-line comment to whomever will be seeing your code.

Also remember that Python is sensitive to indents, so you won’t want to mess around by indenting your comments.

If you’re thinking that you will just remember how your code works, then you’re badly, sorely, laughably mistaken. It’s amazing how quickly you forget how your code is supposed to work. Leave reminders even if it’s a pain in your rump. You won’t regret it.

For a little more on comments, I recommend After Hours Programming.

Featured image is by Hariadhi. See

Published by

Mark R. Vickers

I am a writer, analyst, futurist and researcher. I've spent most of my working life as an editor and manager for research organizations focusing on social, business, technology, HR and management trends. But, perhaps more to the point for this blog, I'm curious about the universe and the myriad, often mysterious relationships therein.

Leave a Reply