ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f(x, *, y=2, **kw):
    return x * y + len(kw)
opts = {"y": 3, "z": 0}
print(f(2, **opts), f(2, z=1, w=1))
  1. A. 6 6
  2. B. 7 4
  3. C. 8 6
  4. D. 7 6

Correct answer: D. 7 6

**opts supplies y = 3 and puts z into kw: 2*3 + 1 = 7. In the second call y keeps its default 2 and kw has two items: 2*2 + 2 = 6.

More Python Programming questions

Exams that ask this topic