ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(sum([[1], [2, 3]], []), sum([[1], [2]], [0]) if False else 'skip')
  1. A. [1, 2, 3] skip
  2. B. [1, 2, 3] [0, 1, 2]
  3. C. 6 skip
  4. D. Error skip

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

sum with a list start concatenates the lists, giving [1, 2, 3]. The second expression takes the else branch, so it prints 'skip' without calling sum on lists of numbers.

More Python Programming questions

Exams that ask this topic