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.
Loading...
Related Quiz
- You have two sets, one containing all employees who attended a training session and another with employees who completed an online assessment. You want to find out who attended the training but did not complete the assessment. Which set operation would help?
- In which type of loop structures can the break statement be used in Python?
- How can you visualize the distribution of a single variable using Seaborn?
- The method _______ is used to remove the first occurrence of a specified value from a list.
- In Python, to create a private attribute in a class, you prefix the attribute name with _______.