Created
September 3, 2009 13:40
-
-
Save NicolasT/180294 to your computer and use it in GitHub Desktop.
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
In [1]: class Person(object): | |
...: def __init__(self, name): | |
...: self.name = name | |
...: | |
...: def __str__(self): | |
...: return self.name | |
...: | |
...: def __add__(self, other): | |
...: return Person('%s and %s' % (self.name, other.name)) | |
...: | |
In [3]: h = Person('Hans') | |
In [4]: g = Person('Grietje') | |
In [5]: h + g | |
Out[5]: <__main__.Person object at 0x958092c> | |
In [6]: (h + g).name | |
Out[6]: 'Hans and Grietje' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment