Error messages are really common, but that doesn’t make them any less frustrating or annoying! Here are some tips for making sense of them, plus a guide to the most common error messages.

Get a printable PDF version of this webpage!

Tip #1: Read the error message from bottom to top.

Error messages sometimes print many lines, tracing how Python ran into the error. If you’re using functions or outside modules, this can get complicated fast. The last line of the error message will state what type of error you got, and the line before that will state where in your program the error occurred.

Tip #2: Backtrack.

If you can’t find an issue with the specific line of code the error message pointed out, you can backtrack in two different ways. The first way is to look at the previous line of code. The second way is to look at the code that’s connected to the error line, such as a function being defined or called, or a variable being defined or used.

Tip #3: Get to know the most common types of errors.

Some error messages are more common than others. These five are the ones you’re most likely to encounter.

SyntaxError

Syntax is the rules about how a certain programming language works. A syntax error in Python usually means you forgot to close parentheses () or quotes '' "", you forgot a colon :, or you put a symbol somewhere Python wasn’t expecting it.

IndentationError

Indented blocks should be used for conditionals, loops, and defining functions. An indentation error means either you indented something that shouldn’t have been indented, you didn’t indent something that needed to be, or your indentations aren’t quite lined up properly.

IndexError

An index error means you used an index value that doesn’t exist (for example, your list has four items in it and you called on index 6).

NameError

A name error happens when Python can’t find anything with the name you used. Either you tried to use a variable or function before you defined it (or didn’t define it at all), or there’s a typo in the name of a variable or function.

TypeError

A type error means that you tried to do something that can’t be done to that type of variable. This most often happens with numbers, when a number needs to be converted from an integer to a string for what you’re trying to do, or vice versa.