mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 23:12:24 +03:00
generator done
This commit is contained in:
22
generators/generator.py
Normal file
22
generators/generator.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user