ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
from functools import reduce
print(reduce(lambda a, b: a * 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2, 3], 0))
  1. A. 123 5
  2. B. 6 -15
  3. C. 123 -15
  4. D. 124 -15

Correct answer: C. 123 -15

The first reduce builds the number 123 digit by digit. The second starts at 0 and subtracts each element, giving 0 - 10 - 2 - 3 = -15.

More Python Programming questions

Exams that ask this topic