ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
it = iter('ab')
print(next(it), list(it), next(it, 'end'))
  1. A. a ['a', 'b'] end
  2. B. a [] end
  3. C. a ['b'] end
  4. 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

Exams that ask this topic