You are required to implement a custom iterator that needs to maintain its internal state between successive calls. Which method should you implement in your class to achieve this?

  • __init__()
  • __iter__()
  • __next__()
  • __str__()
To create a custom iterator that maintains internal state between successive calls, you should implement the __next__() method in your class. This method defines the logic for generating the next value in the iteration and should raise StopIteration when there are no more items to iterate over.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *