0
0
Pythonprogramming~5 mins

Common exception types in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a ValueError in Python?
A ValueError happens when a function receives an argument of the right type but an inappropriate value. For example, trying to convert a letter to an integer.
Click to reveal answer
beginner
Explain TypeError with an example.
A TypeError occurs when an operation or function is applied to an object of an inappropriate type. For example, adding a number and a string together.
Click to reveal answer
beginner
What does IndexError mean?
IndexError happens when you try to access an index that is outside the range of a list or other sequence.
Click to reveal answer
beginner
Describe KeyError in Python dictionaries.
KeyError occurs when you try to access a dictionary key that does not exist.
Click to reveal answer
beginner
What is a ZeroDivisionError?
A ZeroDivisionError happens when you try to divide a number by zero, which is not allowed in math.
Click to reveal answer
Which exception is raised when you try to access a list element with an invalid index?
AIndexError
BKeyError
CTypeError
DValueError
What exception occurs when you try to add a number and a string?
AValueError
BTypeError
CZeroDivisionError
DKeyError
If you try to get a dictionary value using a key that does not exist, which exception is raised?
ATypeError
BIndexError
CValueError
DKeyError
Which exception is raised when you try to convert the string 'abc' to an integer?
AValueError
BTypeError
CZeroDivisionError
DKeyError
What exception occurs when dividing a number by zero?
AValueError
BTypeError
CZeroDivisionError
DIndexError
List and explain three common Python exceptions you might encounter when working with lists and dictionaries.
Think about accessing elements and types.
You got /4 concepts.
    Describe what causes a ValueError and a ZeroDivisionError in Python with simple examples.
    Consider wrong values and division by zero.
    You got /3 concepts.