Error Types

A syntax error is often the easiest to find, and many Python programming environments will identify syntax errors for you as you are programming. A syntax error is essentially a typo, such as misspelling a Python keyword, forgetting parentheses, or using an invalid combination of operators. See examples below:

myStr = "LocoRobo # Missing the ending quotes on the string


prnt(myStr) # Misspelled print()


print(myStr, "Example" # Missing closing parentheses for print()


print(5 +* 2) # Cannot use +* as an operator

Runtime Errors

A runtime error happens when the program is running. When free of syntax errors, a program will compile and run. However, the program could still exit during execution when encountering a problem detected when a particular line of code is run. This is referred to as a “crash” of the program.

There are a wide variety of runtime errors and include:

  1. Referencing an object or variable that does not exist

  2. Indexing part of a list, dictionary, or tuple that does not exist

  3. Dividing a number by 0

  4. Performing an operation of incompatible data types

  5. Attempting to import a module that doesn’t exist

Make sure to reference previous lessons to know how to correctly use parenthesis