Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created April 15, 2023 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengruppetta/387b4e3c79ecfd42d3fbfcc1bed03091 to your computer and use it in GitHub Desktop.
Save stephengruppetta/387b4e3c79ecfd42d3fbfcc1bed03091 to your computer and use it in GitHub Desktop.
class SubstackArticle:
   def __init__(self, number_of_words):
       self.number_of_words = number_of_words
   def __mul__(self, other):
       if isinstance(other, int):
           return SubstackArticle(self.number_of_words * other)
   def __rmul__(self, other):
       return self.__mul__(other)
   def __repr__(self):
       return f"SubstackArticle({self.number_of_words})"
my_article = SubstackArticle(1000)
print(my_article * 3)
# SubstackArticle(3000)
print(3 * my_article)
# SubstackArticle(3000)
print(my_article * "3")
# None
print("3" * my_article)
# None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment