def cube(x): return x*x*x class xplage(object): def __init__(self, fn, deb, fin, pas=1): self.fn = fn self.cpt = deb # initialisation du compteur self.fin = fin self.pas = pas def __iter__(self): return self def next(self): if self.cpt>=self.fin: raise StopIteration k = self.cpt self.cpt += self.pas # incrementation du compteur return self.fn(k) for i in xplage(cube,0,10): print i