ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(len([1, 2, 3] * 2), [1, 2] + [3], [0] * 0, [[0] * 2] * 2 == [[0, 0], [0, 0]])
  1. A. 6 [1, 2] [] True
  2. B. 6 [1, 2, 3] [] True
  3. C. 6 [3] [] True
  4. D. 5 [1, 2, 3] [] True

Correct answer: B. 6 [1, 2, 3] [] True

[1, 2, 3] * 2 repeats the list twice, giving six items. Adding lists concatenates them, and multiplying a list by zero gives an empty list. The nested [[0] * 2] * 2 has two references to the same inner list, which still compares equal.

More Python Programming questions

Exams that ask this topic