ProgrammingEasyProduct-company MCQ pattern
What is printed?
What is printed?
print(list(zip([1, 2, 3], "ab")))
- A. ValueError
- B. [(1, 'a'), (2, 'b')]
- C. [(1, 'ab'), (2, ''), (3, '')]
- 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
- What is printed? python print(" ".join(sorted(set("banana"))))
- What is printed? python try: print(1 / 0, end=" ") except ZeroDivisionError: print("Z", end=" ") finally: print("F")
- What is printed? python print(list(range(10, 0, -3)))
- What is printed? python print(max("apple", "Banana", "cherry"))
- What is printed? python print(round(2.5), round(3.5), round(-0.5))
- What is printed? python class A: count = 0 a1, a2 = A(), A() a1.count += 1 print(A.count, a1.count, a2.count)