ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
x = (1, 2, 3)
y = x + (4,)
z = x * 0
print(len(y), z, x.count(2), x.index(3), 3 in x)
  1. A. 4 (0,) 1 2 True
  2. B. 4 () 1 3 True
  3. C. 4 () 2 2 True
  4. D. 4 () 1 2 True

Correct answer: D. 4 () 1 2 True

Tuple concatenation needs another tuple, (4,). Repeating zero times gives the empty tuple. count and index work like the list versions; 3 sits at index 2.

More Python Programming questions

Exams that ask this topic