ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
def f(a, b, *args, c=0, **kw):
    return a, b, args, c, kw
print(f(1, *[2, 3, 4], c=5, d=6))
  1. A. (1, 2, (3, 4), 5, {'d': 6})
  2. B. (1, 2, (3, 4), 5, {'c': 5, 'd': 6})
  3. C. (1, 2, (3, 4), 0, {'c': 5, 'd': 6})
  4. D. (1, 2, (3, 4, 5), 0, {'d': 6})

Correct answer: A. (1, 2, (3, 4), 5, {'d': 6})

The unpacked list fills b = 2 and the rest (3, 4) go into args as a tuple. c is keyword-only and takes 5; the unknown keyword d lands in kw.

More Python Programming questions

Exams that ask this topic