Certified Associate in Python Programming (PCAP) — Question 21

If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:

Answer options

Correct answer: B

Explanation

The correct syntax to catch multiple exceptions in Python is 'except (ex1, Ex2):', which allows you to specify a tuple of exceptions. Option A is incorrect due to a syntax error, option C uses a comma incorrectly, and option D incorrectly suggests using a '+' operator, which is not valid in this context.