{article Learn Python The Hard Way}{text}{/article}

Notepad++

File ex2.py

# A comment, this is so you can read your program later.
# Anything after the # is ignored by python

print "I could have code like this." # and the comment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."

print "This will run."

Window PowerShell

PS C:\mystuff> python ex2.py
I could have code like this.
This will run.

Study Drill 1

Find out if you were right about what the # character does and make sure you know what it's called (octothorpe or pound character).

Comments

As programs get bigger and more complicated, they get more difficult to read. Formal languages are dense, and it is often difficult to look at a piece of code and figure out what it is doing, or why.

For this reason, it is a good idea to add notes to your programs to explain in natural language what the program is doing. These notes are called comments, and they are marked with the # symbol:

Everything from the # to the end of the line is ignored — it has no effect on the program. The message is intended for the programmer or for future programmers who might use this code. In this case, it reminds the reader about the ever-surprising behavior of integer division.

Study Drill 2

Take your ex2.py file and review each line going backwards. Start at the last line, and check each word in reverse against what you should have typed.

Done

Study Drill 3

Did you find more mistakes? Fix them.

No more mistakes

Study Drill 4

Read what you typed above out loud, including saying each character by its name. Did you find more mistakes? Fix them.

Did not find any more mistakes

Common Student Questions
1:Are you sure # is called the pound character?
I call it the octothorpe and that is the only name that no country uses and that works in every country. Every country thinks their way to call this one character is both the most important way to do it, and also the only way it's done. To me this is simply arrogance and really, y'all should just chill out and focus on more important things like learning to code.
2:If # is for comments, then how come # -*- coding: utf-8 -*- works?
Python still ignores that as code, but it's used as a kind of "hack" or workaround for problems with setting and detecting the format of a file. You also find a similar kind of comment for editor settings.
3:Why does the # in print "Hi # there." not get ignored?
The # in that code is inside a string, so it will be put into the string until the ending " character is hit. These pound characters are just considered characters and aren't considered comments.
4:How do I comment out multiple lines?
Put a # in front of each one.
5:I can't figure out how to type a # character on my country's keyboard?
Some countries use the Alt key and combinations of those to print characters foreign to their language. You'll have to look online in a search engine to see how to type it.
6:Why do I have to read code backwards?
It's a trick to make your brain not attach meaning to each part of the code, and doing that makes you process each piece exactly. This catches errors and is a handy error checking technique.