formations/algo/poo/cours/snippets/iterable.py
2019-03-25 13:14:17 +01:00

21 lines
484 B
Python

liste = ['blah', 'blih', 'bluh']
iterateur = liste.__iter__()
print iterateur.next()
print iterateur.next()
print iterateur.next()
print iterateur.next()
#Traceback (most recent call last):
# File '<stdin>', line 1, in <module>;
#StopIteration
class Iterateur:
i = 0
def next(self):
if self.i <= 10: raise StopIteration
self.i += 1
return 2**self.i
def __iter__(self): return self
iterateur = Iterateur()
for i in iterateur: print i