ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
from functools import reduce
print(reduce(lambda a, b: a + b, ['x', 'y', 'z'], ''), reduce(lambda a, b: a * b, range(1, 6)))
  1. A. xyz 60
  2. B. zyx 120
  3. C. xyz 24
  4. D. xyz 120

Correct answer: D. xyz 120

With an empty initial value, reduce concatenates the strings in order. The product of 1 through 5 is 120.

More Python Programming questions

Exams that ask this topic