Bird
0
0

Which of the following is the correct way to catch both ZeroDivisionError and ValueError in one except block?

easy📝 Conceptual Q2 of 15
Python - Exception Handling Fundamentals
Which of the following is the correct way to catch both ZeroDivisionError and ValueError in one except block?
Aexcept ZeroDivisionError or ValueError:
Bexcept (ZeroDivisionError, ValueError):
Cexcept ZeroDivisionError, ValueError:
Dexcept ZeroDivisionError & ValueError:
Step-by-Step Solution
Solution:
  1. Step 1: Recall syntax for multiple exceptions in one block

    Python requires a tuple of exceptions inside parentheses after except.
  2. Step 2: Identify correct syntax

    Using except (ZeroDivisionError, ValueError): is the correct way.
  3. Final Answer:

    except (ZeroDivisionError, ValueError): -> Option B
  4. Quick Check:

    Multiple exceptions in tuple = correct syntax [OK]
Quick Trick: Use a tuple of exceptions inside parentheses after except [OK]
Common Mistakes:
  • Using 'or' instead of a tuple
  • Separating exceptions with commas without parentheses
  • Using '&' which is invalid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes