Types of Error
1. SyntaxError: Raised when there is an error in Python's syntax.
Example: if True print("Hello")
2. IndentationError: Raised when the indentation is incorrect.
def example():
print("IndentationError!")
3. NameError: Raised when a variable or function name is not defined.
Example: print(unknown_var)
4. TypeError: Raised when an operation is performed on an inappropriate data type.
Example: "Hello" + 5
5. ValueError: Raised when a function receives the correct data type but an invalid
value.
Example: int("abc")
6. IndexError: Raised when accessing an invalid index in a sequence.
Example: [1, 2, 3][5]
7. KeyError: Raised when a dictionary key is not found.
Example: my_dict = {"a": 1}; my_dict["b"]
8. ImportError: Raised when an import statement fails.
Example: import non_existent_module
9. ZeroDivisionError: Raised when division by zero occurs.
Example: 1 / 0