ProgrammingModerateTCS NQT · Python
What is printed?
What is printed?
def f():
try:
return 'a'
finally:
print('f', end=' ')
print(f())- A. f a
- B. a f
- C. a
- D. f
Correct answer: A. f a
The finally block runs before the function actually returns, so 'f ' is printed first and then print outputs the returned 'a'.
More Python Programming questions
- What is printed? python def g(): x = yield 1 print('got', x) y = yield x 2 print('got', y) it = g() print(next(it)) print(it.send(5)) try…
- What is printed? python def mk(): n = 0 def inc(): nonlocal n n += 1 return n return inc a, b = mk(), mk() print(a(), a(), b(), a())
- What is printed? python class C: v = [] n = 0 def add(self, x): self.v.append(x) self.n += 1 a, b = C(), C() a.add(1); b.add(2); b.add(3)…
- What is printed? python print(1 < 2 < 3, 3 > 2 > 2, 1 == 1 in [1], not 1 == 2, 2 3 2)
- What is printed? python a = [[0] 2] 2 a[0][0] = 1 b = [[0] 2 for in range(2)] b[0][0] = 1 print(a, b)
- What is printed? python def f(n): try: if n == 0: raise ValueError return 10 // (n - 1) except ZeroDivisionError: return -1 except…