ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(sum([[1, 2], [3]], []), ''.join(['ab', 'c']), [x for x in 'hey'][::2])
  1. A. [1, 2] abc ['h', 'y']
  2. B. [1, 2, 3] ab ['h', 'e']
  3. C. [1, 2, 3] abc ['h', 'y']
  4. D. [1, 2, 3] abc ['h', 'e']

Correct answer: C. [1, 2, 3] abc ['h', 'y']

sum with a list start concatenates the inner lists, and join concatenates the strings in order. Taking every second character of hey gives h and y.

More Python Programming questions

Exams that ask this topic