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)
- A. 3
- B. f 20
- C. 0123
- 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
- What does the following Python 3 code print? a, b = [8,5,9,9,3], [5,4,3,3] print(list(map(lambda p: p[0] p[1], zip(a, b)))…
- What does the following Python 3 code print? fs = [lambda: i 5 for i in range(3)] print([f() for f in fs])
- What does the following Python 3 code print? d = {} for w in ["nut","kheer","tea","oat","nut","vada"]: d[w[0]] = d.get(w[0], 0) + 1…
- What does the following Python 3 code print? s = "banana split" print("-".join(s.split("n")[1:]))
- What does the following Python 3 code print? from functools import lrucache calls = 0 @lrucache(None) def f(n): global calls calls += 1…
- What does the following Python 3 code print? a, b = set([12,12,1,7,1]), set([12,12,3,10,6,10]) print(sorted(a ^ b), len(a - b))