25 lines
466 B
Python
25 lines
466 B
Python
#Iteration test
|
|
a = (1, 2, 3)
|
|
b = iter(a)
|
|
print(next(b))
|
|
print(next(b))
|
|
print(next(b))
|
|
|
|
class A:
|
|
def __init__(self):
|
|
self.n = 0
|
|
def __init__(self, n):
|
|
self.n = n
|
|
def __iter__(self):
|
|
self.i = 0
|
|
return self
|
|
def __next__(self):
|
|
if self.i > 100 or self.i < -100: raise StopIteration
|
|
z = self.i
|
|
self.i -= self.n
|
|
return z
|
|
c = A(2)
|
|
d = iter(c)
|
|
for x in d:
|
|
print(x)
|