'__iter__in dir(ltrue '__next__in dir(lfalse li iter(literate over concrete collection li li =iter(litrue in functional programming style--or even just generally for readability--writing custom iterators as generator functions is most natural howeverwe can also create custom classes that obey the protocoloften these will have other behaviors ( methodsas wellbut most such behaviors necessarily rely on statefulness and side effects to be meaningful for examplefrom collections abc import iterable class fibonacci(iterable)def __init__(self)self aself self total def __iter__(self)return self def __next__(self)self aself self bself self self total +self return self def running_sum(self)return self total fib fibonacci(fib running_sum( for _i in zip(range( )fib)print(iend=" fib running_sum( next(fib this example is trivialof coursebut it shows class that both implements the iterator protocol and also provides an additional method to return something stateful about its instance since statefulness is for object-oriented programmersin functional programming style we will generally avoid classes like this lazy evaluation