ProgrammingHardGATE CS · Product-company placement
What is printed? (Output lines are shown separated by " / ".)
What is printed? (Output lines are shown separated by " / ".)
def f(*, a, b=2):
return a - b
def g(a, b=2, /):
return a - b
print(f(b=1, a=5), g(5, 1))
for call in (lambda: f(5), lambda: g(a=5)):
try:
call()
except TypeError:
print("TE", end=" ")- A. 4 4 / TE TE
- B. 4 4 / TE
- C. 4 4
- D. SyntaxError
Correct answer: A. 4 4 / TE TE
f takes only keyword arguments (after *), so f(5) fails; g takes only positional arguments (before /), so g(a=5) fails. Keyword order in a call does not matter, and both signatures are valid syntax.
More Python Programming questions
- What is printed? python def outer(fn): def w(a, k): return fn(a, k) 2 return w class C: @outer def val(self, x): return x + 1 @property…
- What is printed? python def log(prefix): def deco(fn): def w(a): return prefix + str(fn(a)) return w return deco @log("A:") @log("B:") def…
- What is printed? python import functools def once(fn): done = [] @functools.wraps(fn) def w(a): if not done: done.append(fn(a)) return…
- What is printed? python class A: def init(self): print("A", end=" ") class B(A): def init(self): print("B", end=" ") class C(B): pass C()…
- What is printed? python class A: def f(self): return "A" class B(A): def f(self): return "B" + super().f() class C(A): def f(self): return…
- What is printed? python class A: x = 1 class B(A): pass class C(A): x = 3 class D(B, C): pass B.x = 2 del B.x print(D.x, D.mro.index(C))