Make a new iterator object for each new iteration : Iter : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Iter »

 

Make a new iterator object for each new iteration


class Squares:
    def __init__(self, start, stop):   
        self.value = start - 1
        self.stop  = stop
    def __iter__(self):                
        return self
    def next(self):                    
        if self.value == self.stop:
            raise StopIteration
        self.value += 1
        return self.value ** 2


X = Squares(15
print [for n in X]                   

print [for n in Squares(15)]       

print list(Squares(13))



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Iter