Computer Science (CS) III Mastery Practice Exam 2026 - Free Computer Science Practice Questions and Study Guide

Session length

1 / 20

Which of the following is the correct syntax for a multiple exception handler?

except (NameError, AttributeError):

The correct syntax for handling multiple exceptions in Python is represented in the choice that states exceptions within parentheses, separated by a comma. This format allows you to catch more than one exception type using a single `except` clause.

Using parentheses to group the exceptions ensures clarity and maintains the correct structure as per Python's syntax requirements. For instance, doing `except (NameError, AttributeError):` will catch both `NameError` and `AttributeError`, allowing you to handle them with the same block of code.

By contrast, the other choices incorrectly format the exception handling construct. One choice uses brackets instead of parentheses, while another lists the exceptions without the necessary conjunction or punctuation. Another choice presents the exceptions without the proper separation, failing to adhere to Python's required syntax. Understanding the correct use of exception handling is crucial, as it enables programmers to manage errors effectively and keep their code robust.

except [NameError, AttributeError dor]:

except NameError AttributeError:

except NameError, AttributeError:

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy