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__)
  1. A. None False ZeroDivisionError
  2. B. None True NoneType
  3. C. ZeroDivisionError False ZeroDivisionError
  4. 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

Exams that ask this topic