Created
February 26, 2022 10:06
-
-
Save AyemunHossain/749caef33a26284c2100e2185e76a5bd to your computer and use it in GitHub Desktop.
Implement Your Own Range Function
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 NewRange: | |
current = 0 | |
def __init__(self, first, last): | |
self.first = first | |
self.last = last | |
def __iter__(self): | |
return self | |
def __next__(self): | |
if NewRange.current<self.last: | |
NewRange.current +=1 | |
return (NewRange.current-1) | |
raise StopIteration | |
rng = NewRange(1,200) | |
for i in rng: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment