ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
def f():
try:
return 'try'
finally:
print('finally', end=' ')
print(f())- A. try finally
- B. try
- C. finally
- D. finally try
Correct answer: D. finally try
finally runs before the return value is handed back to the caller, so its print appears first. The function still returns 'try' and print shows that value after the finally output.
More Python Programming questions
- What is printed? python def g(): try: return 1 finally: return 2 print(g())
- What is printed? python def bracketok(s): pairs = {')': '(', ']': '[', '}': '{'} st = [] for ch in s: if ch in '([{': st.append(ch) elif…
- What is printed? python import sys data = 'first line nsecondn' it = iter(data.splitlines()) print(repr(next(it)), repr(next(it).strip())…
- What is printed? python from collections import deque q = deque() for ch in 'abcd': q.append(ch) if len(q) > 2: q.popleft()…
- What is printed? python a = [1, 2, 3, 4, 5, 6, 7, 8] print(a[::3], a[2::-1], a[-3::2])
- What is printed? python x = [i for i in range(3)] g = (i for i in range(3)) print(x == list(g), list(g), len(x))