Created
December 17, 2021 00:49
-
-
Save Enchan1207/bcbb300684e2cdadf9a7028e32af4dc3 to your computer and use it in GitHub Desktop.
range()を作る
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
# | |
# Custom range() implementation | |
# | |
class CustomRange: | |
def __init__(self, start: int, end: int, pace: int = 1) -> None: | |
self.end = end | |
self.pace = pace | |
self.current = start | |
def __iter__(self): | |
return self | |
def __next__(self) -> int: | |
current = self.current | |
if current + self.pace > self.end: | |
raise StopIteration | |
self.current += self.pace | |
return current | |
custom_range = CustomRange(0, 100, 2) | |
for n in custom_range: | |
print(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment