ProgrammingEasyProduct-company MCQ pattern

What is printed?

What is printed?
print(list(zip([1, 2, 3], "ab")))
  1. A. ValueError
  2. B. [(1, 'a'), (2, 'b')]
  3. C. [(1, 'ab'), (2, ''), (3, '')]
  4. D. [(1, 'a'), (2, 'b'), (3, None)]

Correct answer: B. [(1, 'a'), (2, 'b')]

zip stops when the shortest input runs out. The string "ab" gives only two characters, so only two pairs are made. itertools.zip_longest would pad with None.

More Python Programming questions

Exams that ask this topic