Skip to content

Instantly share code, notes, and snippets.

@JosephTLyons
Created November 22, 2021 20:16
Show Gist options
  • Save JosephTLyons/a7d2122398301186730f6d3b089707bb to your computer and use it in GitHub Desktop.
Save JosephTLyons/a7d2122398301186730f6d3b089707bb to your computer and use it in GitHub Desktop.
An integer class whose digits can be iterated over
class IterInt(int):
def __init__(self, integer):
self.integer = integer
def __iter__(self):
return iter(int(character) for character in str(self.integer))
number = IterInt(4_999_135)
for digit in number:
print(digit, end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment