0% found this document useful (0 votes)
15 views2 pages

Error Types

The document outlines various types of errors in Python programming, including SyntaxError, IndentationError, NameError, TypeError, ValueError, IndexError, KeyError, ImportError, and ZeroDivisionError. Each error type is accompanied by a brief description and an example illustrating the error. This serves as a reference for understanding common programming mistakes in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Error Types

The document outlines various types of errors in Python programming, including SyntaxError, IndentationError, NameError, TypeError, ValueError, IndexError, KeyError, ImportError, and ZeroDivisionError. Each error type is accompanied by a brief description and an example illustrating the error. This serves as a reference for understanding common programming mistakes in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like