Skip to content

Instantly share code, notes, and snippets.

@Enchan1207
Created December 17, 2021 00:49
Show Gist options
  • Save Enchan1207/bcbb300684e2cdadf9a7028e32af4dc3 to your computer and use it in GitHub Desktop.
Save Enchan1207/bcbb300684e2cdadf9a7028e32af4dc3 to your computer and use it in GitHub Desktop.
range()を作る
#
# 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