ProgrammingHardTCS NQT · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? def power(base, exp=2): return base ** exp print(power(3), power(3, 3), power(exp=3, base=2))

  1. A. 9 9 9
  2. B. 9 27 8
  3. C. 6 9 6
  4. D. 9 27 9

Correct answer: B. 9 27 8

power(3) uses the default exp=2 -> 9; power(3,3) -> 27; keyword call power(exp=3, base=2) -> 2**3=8.

More Python Programming questions

Exams that ask this topic