ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(sum([[1], [2, 3]], []))
  1. A. [1, 2, 3]
  2. B. [1, 2, 3, 3]
  3. C. [1, 2]
  4. D. [[1], [2, 3], 9]

Correct answer: A. [1, 2, 3]

sum with an empty list as the start value concatenates the inner lists, because + on lists joins them.

More Python Programming questions

Exams that ask this topic