Skip to content

Instantly share code, notes, and snippets.

@JessicaWachtel
Created February 28, 2025 16:32
class Counter:
def __init__(self, start, end):
self.current = start
self.end = end
def __iter__(self):
return self
def __next__(self):
if self.current > self.end:
raise StopIteration
self.current += 1
return self.current - 1
counter = Counter(1, 5)
for num in counter:
print(num) # Prints 1, 2, 3, 4, 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment