ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
def f(a, b, *, c=10, **kwargs):
    return a + b + c + sum(kwargs.values())
print(f(1, 2, d=3, e=4))
print(f(1, 2, c=100))
  1. A. 20 103
  2. B. 10 103
  3. C. 20 113
  4. D. 10 113

Correct answer: A. 20 103

f(1,2,d=3,e=4): a=1,b=2,c defaults to 10, kwargs={'d':3,'e':4} summing to 7: total 1+2+10+7=20. f(1,2,c=100): a=1,b=2,c=100 explicit, kwargs empty (sum 0): total 1+2+100+0=103.

More Python Programming questions

Exams that ask this topic