1.
NameError
Reason: Variable or function name not defined.
Example: print(x) (when x was never defined)
2. TypeError
Reason: Operation applied to an object of inappropriate type.
Example: "3" + 3
3. ValueError
Reason: Correct data type, but inappropriate value.
Example: int("abc")
4. IndexError
Reason: Index out of range for a list/tuple.
Example: [1, 2, 3][5]
5. KeyError
Reason: Dictionary key not found.
Example: my_dict = {'a': 1}; print(my_dict['b'])
6. AttributeError
Reason: Attribute not found on an object.
Example: 5.append(3)
7. ImportError / ModuleNotFoundError
Reason: Couldn't import a module or object.
Example: import fake_module
8. ZeroDivisionError
Reason: Division by zero.
Example: 10 / 0
9. IndentationError
Reason: Wrong indentation in code.
Example:
def greet():
print("Hi")
10. SyntaxError
Reason: Code syntax is incorrect.
Example: if True print("Hi")
11. FileNotFoundError
Reason: File not found at path.
Example: open("nofile.txt")
12. RuntimeError
Reason: Generic error not part of other categories.
Example: raise RuntimeError("Fail")
13. AssertionError
Reason: An assert statement fails.
Example: assert 2 + 2 == 5
14. MemoryError
Reason: Python runs out of memory.
Example: Creating a huge list.
15. RecursionError
Reason: Too much recursion (no base case).
Example:
def a(): a()
a()
16. FloatingPointError
Reason: Floating point calculation fails (rare).
Needs: Debug mode or math edge cases.
17. StopIteration
Reason: Iterator is exhausted.
Example: next(iter([]))
18. EOFError
Reason: Input() hits End of File.
Example: input() in a file with no data
19. KeyboardInterrupt
Reason: You hit Ctrl+C.
Example: During infinite loop
20. OSError
Reason: OS-related errors like file access, permissions.
Example: Deleting a locked file