Skip to content

Instantly share code, notes, and snippets.

@tarvitz
Created August 31, 2016 21:09
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 tarvitz/6bf0b65c9283fa0e03fb5252abb357c6 to your computer and use it in GitHub Desktop.
Save tarvitz/6bf0b65c9283fa0e03fb5252abb357c6 to your computer and use it in GitHub Desktop.
sum
#!/usr/bin/env python
class A(object):
def __init__(self, obj):
self.obj = obj
def __repr__(self):
return str(self.obj)
def __add__(self, other):
return A(self.obj + other.obj)
def __radd__(self, other):
return A(self.obj + other)
if __name__ == '__main__':
print(A(1) + A(2))
print(sum([A(1), A(2), A(3)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment