Question

Name any four common exceptions in Python.

Updated on May 31, 2025 | By Learnzy Admin | 👁️ Views: 196 students

Solution
✔ Verified

Here are four common exceptions in Python:

  1. TypeError– Raised when an operation or function is applied to an object of inappropriate type.
    Example: len(5)
  2. ValueError– Raised when a function receives an argument of the correct type but inappropriate value.
    Example: int('abc')
  3. IndexError – Raised when a sequence subscript is out of range.
    Example: my_list[10] where my_list has fewer than 11 items.
  4. KeyError – Raised when a dictionary key is not found.
    Example: my_dict['missing_key'] when 'missing_key' does not exist in the dictionary.
Was this solution helpful? 39
Click here to download practice questions on Exception Handling in Python

More Questions on Exception Handling in Python

Question 1

What is the purpose of the else block in exception handling?


View solution
Question 2

What is the use of raise in Python?


View solution
Question 3

How can you catch multiple exceptions in one block?


View solution
Question 4

What is the use of the finally block?


View solution
Question 5

Write the syntax of exception handling in Python.


View solution
Question 6

"Every syntax error is an exception but every exception cannot be a syntax error." Justify the statement.


View solution