ProgrammingHardGATE CS · Product-company placement

What is printed? (Output lines are shown separated by " / ".)

What is printed? (Output lines are shown separated by " / ".)
from functools import partial
def power(base, exp):
    return base ** exp
sq = partial(power, exp=2)
print(sq(5), sq(5, exp=3))
try:
    print(sq(2, 3))
except TypeError:
    print("TypeError")
  1. A. 25 8 / 8
  2. B. 25 125 / 8
  3. C. 25 125 / TypeError
  4. D. 25 25 / TypeError

Correct answer: C. 25 125 / TypeError

Keywords frozen by partial can be overridden by keywords at call time (exp=3 gives 125). sq(2, 3) passes 3 positionally to exp while partial also supplies exp=2, so Python reports multiple values for exp: TypeError.

More Python Programming questions

Exams that ask this topic