ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
e = 5
try:
    1 / 0
except ZeroDivisionError as e:
    pass

try:
    print(e)
except NameError:
    print("NameError")
  1. A. None
  2. B. division by zero
  3. C. NameError
  4. D. 5

Correct answer: C. NameError

At the end of an 'except ... as e' block Python deletes the name e (to break a reference cycle with the traceback). This removes the earlier e = 5 too, so print(e) raises NameError.

More Python Programming questions

Exams that ask this topic