ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
try:
raise TypeError("t")
except (ValueError, TypeError) as e:
print("caught", type(e).__name__)- A. caught ValueError
- B. caught TypeError
- C. caught Exception
- D. TypeError traceback
Correct answer: B. caught TypeError
A tuple of exception types in except matches ANY of them; since TypeError is raised and TypeError is in the tuple, it is caught, and the actual runtime type (TypeError) is reported.
More Python Programming questions
- What is printed? python def f(): return 1, 2, 3 a, b, c = f() print(a, b, c) x = f() print(type(x), x)
- What is printed? python d = {"a": 1, "b": 2} print({v: k for k, v in d.items()})
- What is printed? python s1 = {1, 2, 3} s2 = {2, 3, 4} print(s1 - s2, s1 | s2, s1 & s2)
- What is printed? python print(all([1, 2, 3]), all([1, 0, 3]), any([0, 0, 0]), any([0, 1, 0]))
- What is printed? python x = None print(x or "default") y = 0 print(y or "default") z = "" print(z or "fallback")
- What is printed? python def gen(): try: x = yield 1 except GeneratorExit: print("closing") raise g = gen() next(g) g.close()