ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
try:
try:
raise ValueError
except TypeError:
print("T", end=" ")
finally:
print("F1", end=" ")
except ValueError:
print("V", end=" ")
else:
print("E", end=" ")
finally:
print("F2")- A. V F1 F2
- B. F1 V E F2
- C. T F1 F2
- D. F1 V F2
Correct answer: D. F1 V F2
The inner except TypeError does not match the ValueError, so the inner finally prints F1 and the exception moves outward. The outer except ValueError prints V. else runs only when NO exception happened, so it is skipped, and the outer finally prints F2.
More Python Programming questions
- What is printed? python x = 10 def f(a=x): return a x = 20 print(f())
- What is printed? python print(sum(range(1, 10, 2)), list(range(5))[-1:-4:-1])
- What is printed? python print("abc" < "abd" < "ab", "10" < "9", 10 < 9)
- What is printed? python print({x % 3: x for x in range(7)})
- What is printed? python print([(i, j) for i in range(3) for j in range(i)])
- What is printed? python def g(): x = yield 1 yield x 2 it = g() print(next(it), it.send(5))