ProgrammingHardAccenture pattern

What is printed?

What is printed?
def h(a, b, c):
    return a + b + c
args = [1, 2, 3]
print(h(*args))
args2 = [1, 2]
try:
    print(h(*args2))
except TypeError:
    print("TypeError")
  1. A. 6 TypeError
  2. B. 6 3
  3. C. 3 TypeError
  4. D. TypeError TypeError

Correct answer: A. 6 TypeError

h(*args) unpacks [1, 2, 3] into exactly the 3 required positional parameters, giving 6. h(*args2) supplies only 2 of the 3 required arguments, so Python raises TypeError for a missing argument.

More Python Programming questions

Exams that ask this topic