Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created September 3, 2009 13:40
Show Gist options
  • Save NicolasT/180294 to your computer and use it in GitHub Desktop.
Save NicolasT/180294 to your computer and use it in GitHub Desktop.
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