Lesson 1: Extra material


Error messages


In the main lesson, we ran the following example:


In [ ]:
print "5" + 5

In the example above, we had an error in our code and Python printed an error message. The format of these messages will vary depending on how you're running your code (in a notebook, in a script, or in the interpreter), but there will usually be a few key pieces of useful information contained in the message that will hint at what the problem was:

  1. The line of code where the error occured. The error message above indicates this with a green ----> (if there were more than one line of code here, this would be more informative!).
  2. The general type of error. Above, this is TypeError.
  3. A little about what that error means. This usually follows the error type. Above, this is "cannot concatenate 'str' and 'int' objects").

A good place to start in fixing an error is to go to the problematic line of code and see if you can spot anything wrong, especially involving whatever is hinted at in the message. If that fails, and you really don't understand what the error means, try googling "python [NameOfErrorType]" (e.g. "python TypeError"). This will usually pull up several forums with people who had the same general type of error. When reading through these forums, don't focus too much on the specifics of the problem (it will never been the exact same situation as you) but rather try to look for types of things that can cause the error and how to fix them.

Variations on the print statement


Here's a reference table summarizing the different variations of the print statement. Don't worry about memorizing this; just be aware of the different kinds of things that are possible: