ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
print(list("ab") + ["c"], tuple([1, 2]) * 2)
  1. A. ['ab', 'c'] (1, 2, 1, 2)
  2. B. ['a', 'b', 'c'] (2, 4)
  3. C. ['a', 'b', 'c'] (1, 2, 1, 2)
  4. D. ['ab', 'c'] ((1, 2), (1, 2))

Correct answer: C. ['a', 'b', 'c'] (1, 2, 1, 2)

list("ab") iterates the string, giving ['a', 'b']; + joins two lists. Multiplying a sequence by an integer repeats it, so (1, 2) * 2 is (1, 2, 1, 2), not element-wise doubling.

More Python Programming questions

Exams that ask this topic