ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
def area(w, h=None):
    if h is None:
        h = w
    return w * h
print(area(3), area(3, 4), area(h=2, w=5), area(*[2, 6]))
  1. A. None 12 10 12
  2. B. 9 12 10 TypeError
  3. C. 9 7 10 12
  4. D. 9 12 10 12

Correct answer: D. 9 12 10 12

With h omitted the None sentinel triggers the square case. Keyword arguments may be given in any order, and *[2, 6] unpacks into w and h.

More Python Programming questions

Exams that ask this topic