ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
log = []
def v(x):
log.append(x)
return x
def f(*a, **k):
return a, k
f(v(1), *[v(2)], k=v(3), **{"m": v(4)})
print(log)- A. [1, 2, 3, 4]
- B. [1, 3, 2, 4]
- C. [2, 4, 1, 3]
- D. [4, 3, 2, 1]
Correct answer: A. [1, 2, 3, 4]
Argument expressions are evaluated strictly left to right as written, including those inside * and ** unpackings.
More Python Programming questions
- What is printed? python def outer(fn): print("deco", end=" ") return fn @outer def g(): print("g", end=" ") print("start", end=" ") g(); g()
- What is printed? python def a(fn): def w(): return "a(" + fn() + ")" return w def b(fn): def w(): return "b(" + fn() + ")" return w @a @b…
- What is printed? python import functools def deco(fn): @functools.wraps(fn) def wrapper(a): wrapper.n += 1 return fn(a) wrapper.n = 0…
- What is printed? python def repeat(n): print("R", n, end=" ") def deco(fn): def w(x): return [fn(x) for in range(n)] return w return deco…
- What is printed? python calls = [] def trace(fn): calls.append(fn.name) return fn class C: @trace def m(self): pass @staticmethod @trace…
- What is printed? python def memo(fn): cache = {} def w(n): if n not in cache: cache[n] = fn(n) return cache[n] return w @memo def f(n)…