Last active
October 19, 2019 16:46
-
-
Save JackInTaiwan/64f08a6b5a3bb0107d6cc203b3e2154b to your computer and use it in GitHub Desktop.
python_iteration_4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyIterator: | |
def __init__(self, max_num): | |
self.max_num = max_num | |
def __getitem__(self, key): | |
if key <= self.max_num: | |
return key | |
else: | |
raise IndexError | |
my_iterator = MyIterator(3) | |
for item in my_iterator: | |
print(item) | |
# 0 | |
# 1 | |
# 2 | |
# 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment