ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
def f(*args, **kw):
    return len(args), sorted(kw)
print(f(1, 2, *[3, 4], a=5, **{"b": 6}))
  1. A. (3, ['a', 'b'])
  2. B. (2, ['a', 'b'])
  3. C. (4, ['a', 'b'])
  4. D. (4, ['b', 'a'])

Correct answer: C. (4, ['a', 'b'])

*[3, 4] unpacks into two more positional arguments (4 in total), and **{"b": 6} adds a keyword argument. sorted() on a dict returns its sorted keys.

More Python Programming questions

Exams that ask this topic