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:
# 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.
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
kauser
Highly Voted 4 years, 3 months agoseaverick
Most Recent 10 months agomacxsz
2 years, 6 months agorocky48
2 years, 7 months agotechnoguy
3 years agoDKM
3 years agorbishun
3 years agotanst
3 years, 1 month agoBrodeh
3 years, 8 months agoFulano_de_tal
3 years, 8 months agoleonardodicaprio
3 years, 5 months agoBenKa
4 years, 3 months ago