ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
try:
    print("a")
except Exception:
    print("b")
else:
    print("c")
finally:
    print("d")
  1. A. a d
  2. B. a c d
  3. C. a b d
  4. D. a b c d

Correct answer: B. a c d

No exception is raised, so the try block prints 'a', the else block (which runs exactly when no exception occurred) prints 'c', and finally always runs, printing 'd'. The except block is skipped entirely.

More Python Programming questions

Exams that ask this topic