Untitled
unknown
plain_text
2 years ago
450 B
19
Indexable
Copy code
class LimitationIterator:
def __init__(self, start, limit):
self.start = start
self.limit = limit
def __iter__(self):
return self
def __next__(self):
if self.start <= self.limit:
result = self.start
self.start += 5
return result
else:
raise StopIteration
# Using the iterator
it = LimitationIterator(5, 89)
for num in it:
print(num)Editor is loading...
Leave a Comment