1. Home
  2. Data Science
  3. Python
  4. How is exception handling implemented in Python?

Added 25 Jan 2024

How is exception handling implemented in Python?

  1. try-except block Correct answer
  2. catch-throw block
  3. if-else statement
  4. for-in loop

Correct answer

A. try-except block

13 views

MCQSEXAM

Explanation

Exception handling in Python uses the try-except block. Risky code goes in try; if an error occurs, the matching except clause runs instead of the program crashing. Optional else and finally clauses can follow.

Other languages use try-catch and throw; Python's equivalents are except and raise.

Want more practice? Try the full set of Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs