ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
try:
    list(zip([1, 2], [3], strict=True))
except ValueError:
    print('length mismatch')
print(list(zip([1, 2], [3])))
  1. A. [(1, 3)] length mismatch
  2. B. length mismatch [(1, 3), (2, None)]
  3. C. length mismatch [(1, 3), (2, 3)]
  4. D. length mismatch [(1, 3)]

Correct answer: D. length mismatch [(1, 3)]

With strict=True, zip raises ValueError when the lengths differ, and the except branch prints the message. The second line uses the default behaviour, which stops at the shorter input.

More Python Programming questions

Exams that ask this topic