ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita
What is printed?
What is printed?
try:
try:
1 / 0
except ZeroDivisionError:
raise ValueError('bad')
except ValueError as e:
print(type(e.__context__).__name__, e)- A. ZeroDivisionError bad
- B. ValueError bad
- C. ZeroDivisionError division by zero
- D. ValueError division by zero
Correct answer: A. ZeroDivisionError bad
When an exception is raised while handling another one, Python stores the first as __context__. The printed message is the ValueError text, and the context is the ZeroDivisionError.
More Python Programming questions
- What is printed? python print(sorted([(1, 2), (1,), (0, 9, 9)]))
- What is printed? python print('abcabc'.find('c', 3, 5), 'abcabc'.rfind('a', 0, 4))
- What is printed? python d = {'a': {'b': 1}} print(d.get('a', {}).get('c', 0), d.get('x', {}).get('b'), d['a'].get('b'))
- What is printed? python import math def ndiv(n): c = 0 for i in range(1, math.isqrt(n) + 1): if n % i == 0: c += 1 if i i == n else 2…
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def mid(h): slow = fast = h while fast and…
- What is printed? python from collections import Counter print(''.join(c n for c, n in Counter('tree').mostcommon()))