Debugging – Common Error Messages in Python

Programs have bugs. Very few people write code that has no errors when they run it first. Understanding and fixing errors is an important part of programming.

Errors can be categorized as compile-time and run-time errors. Compile-time errors includes errors detected before the program runs. Compared to other languages (e.g., Java), Python does little checking at compile time, deferring many checks until the code runs. 

Compile-Time Errors

Syntax errors and indentation errors are the most common compile-time errors for beginners. These errors happens when Python does not understand the code you have written. Many of the errors listed below can be detected by a good Python editor or development interface.

The video below demonstrates and explains the common compile-time errors. Video Length: 4:59

 

Run-Time Errors 

Run-time errors occur when a program executes. A run-time error happens when Python understands what you are saying, but runs into trouble following the given instructions.  Some run-time errors are easy to fix. But others can be the result of incorrect actions that happened earlier in the code and identification may take all your debugging skills.

A program without a runtime error may still have a bug. The program may not print anything, may produce an incorrect result, or may have an infinite loop. Such errors are typically caused by a logic error. See Common Mistakes not Producing an Error Message

The video below demonstrates and explains the common run-time errors. Video Length: 4:53