To make the custom objects of a class iterable using a for loop, one should implement the _______ and _______ methods.

  • __for__ and __loop__
  • __iter__ and __next__
  • __iterator__ and __iter__
  • __next__ and __previous__
To enable custom objects of a class to be iterable, you need to implement the __iter__ and __next__ methods. The __iter__ method returns the iterator object itself, and the __next__ method defines how to iterate over the object.
Add your answer
Loading...

Leave a comment

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