Exercise 2 is entitled “Comments and Pound Characters.” As we saw in the practice exercises in Ex. 1, comments can be used to add bits of English to our code for interpretation or as a tool to disable certain parts of your program. This exercise just lays that idea out more clearly.
ex2.py 1 # A comment, this is so you can read your program later. 2 # Anything after the # is ignored by python. 3 4 print "I could have code like this." # and the comment after is ignored 5 6 # You can also use a comment to "disable" or comment out a piece of code: 7 # print "This won't run." 8 9 print "This will run."
Not too difficult. Much like the last exercise, we’re simply writing a few lines to print and manipulating which ones will actually print by using comments. Let’s get into the study drills.
- Find out if you were right about what the # character does and make sure you know what it’s called (octothorpe or pound character). (Get with the times, Zed. Everyone knows it’s a hashtag.)
- Take your ex2.py file and review each line going backward. Start at the last line, and check each word in reverse against what you should have typed.
- Did you find more mistakes? Fix them.
- Read what you previously typed out loud, including saying each character by its name. Did you find more mistakes? Fix them.
These are some great study drills. I learned the “backwards” trick in 9th grade from my high school English teacher. Essentially, you’re forcing your brain to parse each word individually as a sort of spell-check. When you read forward, your brain instead looks at chunks of phrases and can ignore spelling errors because it knows what to expect, in a sense. Additionally, reading things out loud is another great way to engage your mind a little differently and force you to examine things more closely. Different strategy, same purpose. I wholeheartedly endorse these methods.