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")
  1. A. (1, 2, 3, 4) True / (1, 2, 3, 4)
  2. B. (1, 2, 3, 4) True / TE
  3. C. TE
  4. 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

Exams that ask this topic