Exercise 2: Comments And Pound Characters

Comments are very important in your programs. They are used to tell you what something does in English, and they also are used to disable parts of your program if you need to remove them temporarily. Here's how you use comments in Python:

1
2
3
4
5
6
7
8
9
# 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."

From now on, I'm going to write code like this. It is important for you to understand that everything does not have to be literal. Your screen and program may visually look different, but what's important is the text you type into the file you're writing in your text editor. In fact, I could work with any text editor and the results would be the same.

What You Should See

$ python ex2.py 
I could have code like this.
This will run.
$

Again, I'm not going to show you screenshots of all the terminals possible. You should understand that the above is not a literal translation of what your output should look like visually, but that the text between the first $ python ... and last $ lines will be what you focus on.

Extra Credit

  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).
  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.
  3. Did you find more mistakes? Fix them.
  4. Read what you typed above out loud, including saying each character by its name. Did you find more mistakes? Fix them.