ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
for kw in [{}, {"strict": True}]:
try:
print(list(zip("ab", [1, 2, 3], **kw)), end=" ")
except ValueError:
print("VE", end=" ")
print(list(enumerate("xy", start=5)))- A. [('a', 1), ('b', 2)] VE [(5, 'x'), (6, 'y')]
- B. [('a', 1), ('b', 2)] [('a', 1), ('b', 2)] [(5, 'x'), (6, 'y')]
- C. VE VE [(5, 'x'), (6, 'y')]
- D. [('a', 1), ('b', 2)] VE [(0, 'x'), (1, 'y')]
Correct answer: A. [('a', 1), ('b', 2)] VE [(5, 'x'), (6, 'y')]
zip normally stops at the shortest input; with strict=True (Python 3.10+) unequal lengths raise ValueError. enumerate's start only changes the counter values.
More Python Programming questions
- What is printed? python def g(): yield from range(2) yield from "ab" return "done" def h(): r = yield from g() yield r print(list(h())…
- What is printed? python def evens(): n = 0 while True: yield n n += 2 def take(k, it): return [next(it) for in range(k)] e = evens()…
- What is printed? python def pipeline(): nums = (n for n in range(10)) sq = (n n for n in nums if n % 2) big = (s for s in sq if s > 10)…
- What is printed? python def g(): print("a", end=" ") x = yield print("b", x, end=" ") yield x 2 it = g() print(it.send(None), end=" ")…
- What is printed? python def g(): try: yield 1 except GeneratorExit: print("exit", end=" ") yield 2 it = g() next(it) try: it.close()…
- What is printed? (Output lines are shown separated by " / ".) python it = iter([1, 2, 3, 4, 5, 6]) print([(a, b) for a, b in zip(it, it)]…