ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
def n(**kw):
    return kw
print(n(**{"a": 1}, **{"b": 2}))
  1. A. {'a': 1, 'b': 2}
  2. B. TypeError: duplicate keys
  3. C. {'a': 1}
  4. D. {'b': 2}

Correct answer: A. {'a': 1, 'b': 2}

Python allows unpacking multiple dicts with ** into a single call as long as their keys don't collide; here 'a' and 'b' are distinct, so both end up merged in kw.

More Python Programming questions

Exams that ask this topic