ProgrammingHardInfosys pattern

What is printed?

What is printed?
def p(a, b, c=3):
    return a, b, c
d = {"a": 1, "b": 2, "c": 10}
print(p(**d))
  1. A. (1, 2, 3)
  2. B. (1, 2, 10)
  3. C. TypeError
  4. D. (1, 2, 10, {})

Correct answer: B. (1, 2, 10)

**d unpacks the dict into keyword arguments a=1, b=2, c=10, overriding the default c=3 since the dict supplies its own value for c.

More Python Programming questions

Exams that ask this topic