The Wayback Machine - https://web.archive.org/web/20250312181645/https://www.geeksforgeeks.org/quizzes/python-exception-handling-quiz/

Python Exception Handling quiz

Last Updated :
Discuss
Comments

Question 1

What is an exception in Python?

  • A syntax error

  • A runtime error

  • A logical error

  • A compile-time error

Question 2

How can you handle exceptions in Python?

  • Using if-else statements

  • Using try-except blocks

  • Using switch-case statements

  • Using for loops

Question 3

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

  • To define a block of code that will be executed if an exception occurs

  • To specify the code to be executed regardless of whether an exception occurs or not
     

  • To catch and handle specific exceptions
     

  • To raise a custom exception
     

Question 4

Which of the following statements is used to raise a custom exception in Python?

  • throw

  • raise 

  • catch

  • except

Question 5

What will be the output of the following code?

try:
   result = 10 / 0
except ZeroDivisionError:
   result = "Infinity"

print(result)
 

  • 10

  • "Infinity"

  • ZeroDivisionError

  • None

Question 6

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

  • To handle exceptions

  • To specify code that will be executed if no exceptions are raised

  • To define custom exceptions

  • To skip the execution of the block if an exception occurs

Question 7

How can you catch multiple exceptions in a single except block?

  • Using a comma-separated list of exceptions

  • Using nested try-except blocks

  • By defining a custom exception

  • Using the catch keyword

Question 8

 What is the purpose of the assert statement in Python exception handling?

  • To catch and handle exceptions

  • To raise a custom exception

  • To check if a given expression is true, otherwise raise an 'AssertionError'

  • To ignore exceptions

Question 9

What does the finally block execute if an exception is raised and not caught?

  • It doesn't execute

  • It executes before the exception is raised

  • It executes after the exception is raised

  • It executes only if the exception is caught

Question 10

What is the purpose of the with statement in Python exception handling?

  • To create a new exception

  • To simplify resource management using context managers

  • To catch and handle exceptions

  • To define a custom exception

"This course is very well structured and easy to learn. Anyone with zero experience of data science, python or ML can learn from this. This course makes things so easy that anybody can learn on their own. It's helping me a lot. Thanks for creating such a great course."-  Ayushi Jain | Placed at Microsoft

Now's your chance to unlock high-earning job opportunities as a Data Scientist! Join our Complete Machine Learning & Data Science Program and get a 360-degree learning experience mentored by industry experts.

Get hands on practice with 40+ Industry Projects, regular doubt solving sessions, and much more. Register for the Program today!

There are 24 questions to complete.

Take a part in the ongoing discussion