If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:
If you need to handle multiple exceptions in a single except branch in Python, you should use parentheses to group them. Writing 'except (Ex1, Ex2):' correctly instructs Python to handle both Ex1 and Ex2 exceptions. This syntax allows you to specify a tuple of exception classes that the except clause will catch, making option B the correct choice.
Answer is C, but with brackets inserted around (Ex1, Ex2) - or B uppercase Ex1
B. except (Ex1, Ex2):
The Answer is D: try: pass except TypeError+ZeroDivisionError: pass except: pass
ur code is giving issue. It can't be an answer
# Answer is B. Point of Q is, you need to use () with except when more than 1. try: # TypeError: can only concatenate str (not "int") to str print( 'five' + 1 ) # ZeroDivisionError: division by zero print ( 5 / 0) except (TypeError, ZeroDivisionError): print('An error occured.')
B should be the answer, but aren't the Exception name case sensitive? In which case, B is not the answer.
try: # TypeError: can only concatenate str (not "int") to str print( 'five' + 1 ) # ZeroDivisionError: division by zero print ( 5 / 0) except (TypeError, ZeroDivisionError): #correct #except TypeError, ZeroDivisionError: #SyntaxError: multiple exception types must be parenthesized #except TypeError ZeroDivisionError: #SyntaxError: invalid syntax #except TypeError + ZeroDivisionError: #TypeError: unsupported operand type(s) for +: 'type' and 'type' print('An error occured.') Output - An error ocurred Ans is B
b. except (Ex1, Ex2):
B is corrrect answer
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write: a. except Ex1 Ex2: b. except (Ex1, Ex2): c. except Ex1, Ex2: d. except Ex1 + Ex2:
Should be D
Answer should be A