ProgrammingHardIBM · Deloitte · Product Company SDE

What does the following Python 3 code print? def f(a, *, b): return a + b try: print(f(1, 2)) except TypeError: print("err")

  1. A. err
  2. B. 1 2
  3. C. TypeError: f() takes 1 argument
  4. D. 3

Correct answer: A. err

The bare * forces b to be supplied only as a keyword; calling f(1, 2) passes 2 positionally and raises a TypeError, caught here.

More Python Programming questions

Exams that ask this topic