ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f(**kw):
    return list(kw)
print(f(b=1, a=2), f(**dict(z=0), y=1), f(**{"1": 1}))
  1. A. ['a', 'b'] ['y', 'z'] ['1']
  2. B. ['b', 'a'] ['z', 'y'] TypeError
  3. C. ['b', 'a'] ['y', 'z'] ['1']
  4. D. ['b', 'a'] ['z', 'y'] ['1']

Correct answer: D. ['b', 'a'] ['z', 'y'] ['1']

**kw preserves the order in which keyword arguments were passed (guaranteed since Python 3.6). Keys unpacked with ** only have to be strings, not valid identifiers, so '1' is accepted.

More Python Programming questions

Exams that ask this topic