Definizione degli iteratori

This commit is contained in:
Fabio Scotto di Santolo
2021-07-01 20:27:58 +02:00
parent cdd79e5f15
commit dda7230d2b
2 changed files with 21 additions and 0 deletions

0
iterators/__init__.py Normal file
View File

21
iterators/main.py Normal file
View File

@@ -0,0 +1,21 @@
class MyIterator:
def __iter__(self):
self.__myattr = 2
return self
def __next__(self):
if self.__myattr < 300:
n = self.__myattr
self.__myattr *= 2
return n
else:
raise StopIteration
def main():
for x in MyIterator():
print(x)
if __name__ == '__main__':
main()