Problem Statement
Which statement is true for a custom iterator object?
Explanation
An iterator needs dunder iter that returns self and dunder next that yields the next value or raises StopIteration.
You do not need inheritance or a generator; any object with these methods is an iterator.
Code Solution
SolutionRead Only
class Count:
def __init__(self,n): self.i=0; self.n=n
def __iter__(self): return self
def __next__(self):
if self.i>=self.n: raise StopIteration
self.i+=1; return self.i