Created
September 22, 2016 07:19
-
-
Save macrat/0cb2d2c8e4d0331f8f5d13e92b3e96a3 to your computer and use it in GitHub Desktop.
addとraddが両方実装されてたらどっちが呼ばれるのか、というはなし。addだった。
This file contains hidden or 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
class Tea: | |
def __init__(self, n): | |
self.n = n | |
def __add__(self, v): | |
print('add of {}'.format(self.n)) | |
def __radd__(self, v): | |
print('radd of {}'.format(self.n)) | |
class Teb: | |
def __init__(self, n): | |
self.n = n | |
def __add__(self, v): | |
print('add of {}'.format(self.n)) | |
def __radd__(self, v): | |
print('radd of {}'.format(self.n)) | |
if __name__ == '__main__': | |
Tea(1) + Tea(2) # add of 1 | |
Tea(3) + Teb(4) # add of 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment