ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? def f(): try: return 3 finally: print("f", end=" ") x = f() + 17 print(x)

  1. A. 3
  2. B. f 20
  3. C. 0123
  4. D. 17

Correct answer: B. f 20

A finally block always runs before the function actually returns; a return inside finally would override the earlier return value. Output: f 20.

More Python Programming questions

Exams that ask this topic