feat: add iter_test.py
This commit is contained in:
20
iter_test.py
Executable file
20
iter_test.py
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
class MyNumbers:
|
||||||
|
def __iter__(self):
|
||||||
|
self.a = 1
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
if self.a <= 10:
|
||||||
|
x = self.a
|
||||||
|
self.a += 1
|
||||||
|
return x
|
||||||
|
else:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
myNumbers = MyNumbers()
|
||||||
|
for x in iter(myNumbers):
|
||||||
|
print(x)
|
||||||
Reference in New Issue
Block a user