ProgrammingHardTCS NQT · Accenture

What is printed?

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

Correct answer: C. strict

zip with strict=True, available from Python 3.10, raises ValueError when the inputs have different lengths. Without strict, zip silently stops at the shorter input.

More Python Programming questions

Exams that ask this topic