ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
try:
    try:
        {}["x"]
    except KeyError as k:
        raise RuntimeError("r") from None
except RuntimeError as e:
    print(type(e.__context__).__name__, e.__cause__, e.__suppress_context__)
  1. A. NoneType None True
  2. B. KeyError None True
  3. C. KeyError None False
  4. D. NoneType None False

Correct answer: B. KeyError None True

`raise X from None` sets __cause__ = None and __suppress_context__ = True, which hides the KeyError in tracebacks; but __context__ is still recorded as the KeyError.

More Python Programming questions

Exams that ask this topic