The Iterator Protocol : Iterator : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Iterator »

 

The Iterator Protocol


class Fibs:
    def __init__(self):
        self.a = 0
        self.b = 1
    def next(self):
        self.a, self.b = self.b, self.a+self.b
        return self.a
    def __iter__(self):
        return self

fibs = Fibs()
for f in fibs:
   if f > 100:
      print f
      break



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Class
» Iterator