Created
August 31, 2016 21:09
-
-
Save tarvitz/6bf0b65c9283fa0e03fb5252abb357c6 to your computer and use it in GitHub Desktop.
sum
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
#!/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