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)
- A. 7
- B. 13
- C. 0127
- 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
- What does the following Python 3 code print? a, b = [3,1,8,5,4,7], [7,4,2,5] print(list(map(lambda p: p[0] p[1], zip(a, b)))…
- What does the following Python 3 code print? d = {} for w in ["kheer","ghee","bun","nut","cake","jam"]: d[w[0]] = d.get(w[0], 0) + 1…
- What does the following Python 3 code print? a, b = 18, 5 print(a // b, a % b, -a // b, -a % b)
- What does the following Python 3 code print? a = [[0] 2] 2 a[0][0] = 7 print(a)
- What does the following Python 3 code print? print(sum(x x for x in range(30) if x % 4 == 1))
- What does the following Python 3 code print? def f(x, acc=[]): acc.append(x) return acc f(8) f(4) print(f(8))