ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
def f(a, *args, key=None, **kw):
    return (a, args, key, sorted(kw))
print(f(1, 2, 3, key='k', z=0, y=9))
  1. A. (1, (2, 3), None, ['y', 'z'])
  2. B. (1, (2, 3), 'k', ['y', 'z'])
  3. C. (1, (2, 3), 'k', ['z', 'y'])
  4. D. (1, [2, 3], 'j', ['y', 'z'])

Correct answer: B. (1, (2, 3), 'k', ['y', 'z'])

Positional extras go into args, keyword-only key is set to 'k', and the other keywords go into kw. sorted(kw) lists the names in order.

More Python Programming questions

Exams that ask this topic