ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f(*args):
    args += (99,)
    return args
t = (1, 2)
print(f(*t), t, f(t))
  1. A. (1, 2, 99) (1, 2, 99) ((1, 2), 99)
  2. B. (1, 2, 99) (1, 2) ((1, 2), 99)
  3. C. (1, 2, 99) (1, 2) TypeError
  4. D. (1, 2, 99) (1, 2) ((1, 2, 99), 99)

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

*args is always a new tuple, so += builds another tuple and never affects t. Passing t without * makes it a single argument, so args is ((1, 2),).

More Python Programming questions

Exams that ask this topic