Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
a = (1,)
print(a * 3, len(a * 0))
What is printed?
  1. A. (1, 1, 1) 1
  2. B. (1,) 0
  3. C. (1, 1, 1) 3
  4. D. (1, 1, 1) 0

Correct answer: D. (1, 1, 1) 0

Tuple multiplication repeats the tuple, so a * 3 is (1, 1, 1); multiplying by 0 gives the empty tuple of length 0.

More Coding Interview Problems questions

Exams that ask this topic