ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

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

  1. A. 7
  2. B. 13
  3. C. 0127
  4. D. f 20

Correct answer: D. 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