Question
Name any four common exceptions in Python.
Solution
✔ Verified
Here are four common exceptions in Python:
- TypeError– Raised when an operation or function is applied to an object of inappropriate type.
Example: len(5) - ValueError– Raised when a function receives an argument of the correct type but inappropriate value.
Example: int('abc') - IndexError – Raised when a sequence subscript is out of range.
Example: my_list[10] where my_list has fewer than 11 items. - KeyError – Raised when a dictionary key is not found.
Example: my_dict['missing_key'] when 'missing_key' does not exist in the dictionary.
Click here to download practice questions on
Exception Handling in PythonMore Questions on Exception Handling in Python
Question 6
"Every syntax error is an exception but every exception cannot be a syntax error." Justify the statement.
View solution