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, /, c, *, d):
return (a, b, c, d)
args = (1, 2)
kw = {"c": 3, "d": 4}
print(f(*args, **kw), f(1, 2, 3, d=4) == f(*[1, 2, 3], **{"d": 4}))
try:
f(1, 2, 3, 4)
except TypeError:
print("TE")- A. (1, 2, 3, 4) True / (1, 2, 3, 4)
- B. (1, 2, 3, 4) True / TE
- C. TE
- D. (1, 2, 3, 4) False / TE
Correct answer: B. (1, 2, 3, 4) True / TE
c may be given by keyword, so **kw supplies c and d. d is keyword-only (after *), so passing four positional arguments raises TypeError.
More Python Programming questions
- What is printed? python class A: def init(self, kw): print("A", sorted(kw), end=" ") class B(A): def init(self, b=0, kw): print("B", end="…
- What is printed? python class Base: def run(self): return self.step() def step(self): return "base" class Child(Base): def step(self)…
- What is printed? python class Meta(type): def new(m, name, bases, ns): ns["kind"] = name.upper() return super().new(m, name, bases, ns)…
- What is printed? python class S: slots = ("a",) class T(S): pass t = T() t.a = 1 t.b = 2 s = S() try: s.b = 2 except AttributeError…
- What is printed? python class Account: rate = 0.05 def init(self, bal): self.bal = bal def interest(self): return self.bal self.rate a =…
- What is printed? python def countergen(): c = 0 while True: cmd = yield c if cmd == "reset": c = 0 else: c += 1 g = countergen()…