ProgrammingVery hardPython · GATE DA · Advanced
What is printed?
What is printed?
try:
try:
1 / 0
except ZeroDivisionError as e:
raise ValueError('bad') from None
except ValueError as v:
print(v.__cause__, v.__suppress_context__, type(v.__context__).__name__)- A. None False ZeroDivisionError
- B. None True NoneType
- C. ZeroDivisionError False ZeroDivisionError
- D. None True ZeroDivisionError
Correct answer: D. None True ZeroDivisionError
'from None' sets __cause__ to None and __suppress_context__ to True, but __context__ is still recorded automatically as the ZeroDivisionError being handled.
More Python Programming questions
- What is printed? python def deco(tag): def w(f): def g(a): return f'<{tag}>' + f(a) + f'</{tag}>' return g return w @deco('b') @deco('i')…
- What is printed? python g = (x 2 for x in range(3)) lst = [1, 2, 3] h = (y for y in lst if y > n) n = 1 lst = [5] print(list(g), list(h))
- What is printed? python class A: def new(cls, v): print('new', v) return super().new(B) if v else super().new(cls) def init(self, v)…
- What is printed? python d = {'a': 1, 'b': 2, 'c': 3} del d['a'] d['a'] = 0 d |= {'b': 9, 'z': 4} print(list(d.items()), min(d, key=d.get))
- What is printed? python x = [1, 2, 3, 4, 5, 6] for i in x: if i % 2 == 0: x.remove(i) d = {'a': 1} try: for k in d: d[k + 'x'] = 0 except…
- What is printed? python words = ['bb', 'a', 'cc', 'd', 'aa'] print(sorted(words, key=len, reverse=True)) print(sorted(words, key=lambda w…