This is a compilation of all the common types of Errors found in Python. These errors, also known as “run-time” errors, since they occur during the execution of the program, can be pretty hard to fix if you don’t know what’s causing it. We’ll explain each error alongside an example to help you identify and locate similar errors.
Note: Head over to our Python Exception handling tutorial to find out how to handle these errors properly, should you encounter them.
Common Python Errors:
Name Error: Error thrown when an object (like a variable) could not be found. Usually caused due to naming issues or undeclared variables.
Type Error: An Error thrown when an operation or function is applied to an object of an inappropriate type.
Memory Error: A Error thrown when your program has created too many objects and is out of memory space. Also referred to as, “Out of Memory” error. Commonly caused by infinite loops, where objects are created infinitely.
Module NotFound Error: An Error thrown when a module cannot be found for import. Either the name of the module was written incorrectly or the module was not installed/downloaded.
Import Error: Error thrown when a specified function can not be found. Similar to the “Module NotFound Error”, this is caused when you try importing a function that does not exist from a module.
Key Error: Error thrown when a key is not found. This error is caused in Dictionaries where key:value pairs are used.
Value Error: It is thrown when a function’s argument is of an inappropriate type.
Syntax Error: Raised by the parser when a syntax error is encountered. A good IDE will point the area where the syntax error occurred, and maybe even identify the problem correctly.
Zero Division Error: An Error thrown when the second operator in the division is zero. Usually crops up during arithmetic calculations.
Indentation Error: Raised when there is an incorrect indentation. Similarly to Syntax Errors, IDE will help you identify this.
Less common Python Errors:
Overflow Error: Raised when the result of an arithmetic operation is too large to be represented. Variables have a fixed size, and if this size is exceeded, this error will occur. Although Python3 will convert a normal integer to a long integer (which can store more data) automatically if needed.
Run-Time Error: When an error occurs that does not fall under any category, a “Run-Time” error message will be shown.
Floating Point Error: Raised when a floating point operation fails.
System Exit: Raised by the
Unbound Local Error: Raised when trying to access a local variable in a function but no value has been assigned to it.
Assertion Error: Raised when an assert statement fails.
This marks the end of the Python Errors tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.