ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from functools import partial
def power(base, exp):
    return base ** exp
sq = partial(power, exp=2)
cube_of_three = partial(power, 3)
print(sq(7), cube_of_three(2), sq(base=5))
  1. A. 49 8 25
  2. B. 49 9 Error
  3. C. 7 9 25
  4. D. 49 9 25

Correct answer: D. 49 9 25

partial(power, exp=2) fixes the keyword exp, so sq(7) is 7**2. partial(power, 3) fixes base = 3 positionally, so cube_of_three(2) is 3**2 = 9. sq(base=5) passes base by keyword, giving 25.

More Python Programming questions

Exams that ask this topic