0% found this document useful (0 votes)
38 views1 page

Python Error Types

The document outlines various Python error types, including SyntaxError, TypeError, and NameError, each with a brief description and example. It explains how these errors occur, such as syntax issues, incompatible data types, and undefined variables. Additional errors like IndexError, ValueError, AttributeError, KeyError, and ZeroDivisionError are also defined with corresponding examples.

Uploaded by

anukarthik100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views1 page

Python Error Types

The document outlines various Python error types, including SyntaxError, TypeError, and NameError, each with a brief description and example. It explains how these errors occur, such as syntax issues, incompatible data types, and undefined variables. Additional errors like IndexError, ValueError, AttributeError, KeyError, and ZeroDivisionError are also defined with corresponding examples.

Uploaded by

anukarthik100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PYTHON ERROR TYPES

SyntaxError Error in the structure of the code, such as missing punctuation print("Hello, world!'
or incorrect syntax. (Mismatched quotes)

TypeError Incompatible data types used in an operation, such as adding a x = "Hello" + 10


string to an integer. (Trying to add a string and an integer)
NameError Referencing a variable or function that hasn't been defined yet. print(my_var)
(Where my_var is not defined)
IndexError Trying to access an index that is out of range in a list, tuple, or my_list = [1, 2, 3]
string. print(my_list[5])
(Accessing index that doesn't exist)
ValueError A valid type is given, but with an inappropriate value. int("abc")
(Trying to convert a non-numeric string
to an integer)

AttributeError Trying to access a method or attribute that doesn't exist for the 'Hello'.append(" World")
object. (String objects don't have an append
method)
KeyError Trying to access a dictionary with a key that doesn't exist. my_dict = {'name': 'Jakins'}
print(my_dict['age'])
(Key 'age' does not exist in the dictionary)
ZeroDivisionError Attempting to divide by zero. x = 10 / 0 (Dividing by zero)

You might also like