- NameError
- If not defined or wrongly defined.
print(a + b)
a = 0
b = 5
# NameError: name 'a' is not defined
- TypeError
- If an operation applied to inappropriate types.
print("15" + 2)
# TypeError: unsupported operand type(s) for +: 'int' and 'str'
- ValueError
- Correct type but with inappropriate value.
print(int("five"))
# ValueError: invalid literal for int() with base 10: 'five'
- ZeroDivisionError
a = 0
b = 5
print(b / a)
# ZeroDivisionError: division by zero
- SyntaxError
# 1
new_list = [1, 2, 3, 4, 5
print(new_list)
# 2
i := 3
# SyntaxError: invalid syntax
- OSError
f = open('i_dont_exist.txt')
# FileNotFoundError: [Errno 2] No such file or directory: 'i_dont_exist.txt'
- ImportError
from math import square
# ImportError: cannot import name 'square'
- EOFerror
- One case can be when input has no data to read.
first = input()
second = input()
third = input() # this was not expected
# EOFError: EOF when reading a line
- IndexError
new_list = ['the only element']
print(new_list[1])
# IndexError: list index out of range