You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
440 B
Python
21 lines
440 B
Python
# Итераторы
|
|
class MyRangeIterator:
|
|
def __init__(self, top):
|
|
self.top = top
|
|
self.current = 0
|
|
|
|
def __iter__(self):
|
|
return self
|
|
|
|
def __next__(self):
|
|
if self.current >= self.top:
|
|
raise StopIteration
|
|
|
|
current = self.current
|
|
self.current += 1
|
|
|
|
return current
|
|
|
|
counter = MyRangeIterator(3)
|
|
for it in counter:
|
|
print(it) |