next() function with iterators in a loop in Python

Question:
How does the next() function interact with iterators in a loop in Python?

  1. It retrieves the next item from the iterator and advances the iterator to the following item
  2. It resets the iterator to its initial state
  3. It skips the next item in the iterator and returns the subsequent one
  4. It terminates the iteration process immediately
Answer:
A - is the correct answer. The next() function is used with iterators to retrieve the next item in the sequence. When used in a loop, it advances the iterator to the next item, and when there are no more items, it raises a StopIteration exception, which can be used to break a loop if not caught