Files
Python-tutorial/generators/generator.py
2025-03-24 16:00:37 +00:00

22 lines
399 B
Python

class MyGen():
current = 0
def __init__(self, first, last):
self.first = first
self.last = last
def __iter__(self):
return self
def __next__(self):
if MyGen.current < self.last:
num = MyGen.current
MyGen.current += 1
return num
raise StopIteration
gen = MyGen(0,100)
for i in gen:
print(i)