Python Errors Guide
Python Errors Guide
SyntaxError
Example:
if True print('Hello')
IndentationError
Example:
def greet():
print('Hi')
NameError
Example:
print(age)
TypeError
Example:
'2' + 2
ValueError
Occurs when a function receives an argument of right type but inappropriate value.
Example:
int('abc')
IndexError
Example:
KeyError
Example:
d = {'name':'John'}; print(d['age'])
# KeyError: 'age'
AttributeError
Example:
'hello'.push('o')
ModuleNotFoundError
Common Python Errors - Definitions & Examples
Example:
import notamodule
ImportError
Example:
ZeroDivisionError
Example:
5/0
OverflowError
Example:
FileNotFoundError
Example:
open('nofile.txt')
RuntimeError
A generic error raised when an error is detected that doesn't fall in other categories.
Example:
AssertionError
Example:
assert 2 + 2 == 5
# AssertionError