ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
it = iter('ab')
print(next(it), list(it), next(it, 'end'))- A. a ['a', 'b'] end
- B. a [] end
- C. a ['b'] end
- D. a ['b'] b
Correct answer: C. a ['b'] end
next takes the first letter, list consumes the rest, and the exhausted iterator returns the default end.
More Python Programming questions
- What is printed? python print([n for n in range(8) if n and n & (n - 1) == 0])
- What is printed? python import heapq a = [5, 1, 4] heapq.heapify(a) print([heapq.heappop(a) for in range(len(a))], a)
- What is printed? python vals = [y for x in range(5) if (y := x x) % 2 == 0] print(vals)
- What is printed? python from functools import partial f = partial(int, base=2) print(f('101'), f('11', base=10))
- What is printed? python print(list(zip([(1, 'a'), (2, 'b')])))
- What is printed? python print(1 if 0 else 2 if 1 else 3, (lambda: 1 if False else 'x')())