Skip to content

Instantly share code, notes, and snippets.

@taiki45
Last active December 21, 2015 02:59
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 taiki45/6239436 to your computer and use it in GitHub Desktop.
Save taiki45/6239436 to your computer and use it in GitHub Desktop.
In [1]: class ListA(object):
...: def __init__(self, x, y):
...: self.x = x
...: self.y = y
...: def sum(self):
...: return self.x + self.y
...:
In [2]: a = ListA(4, 5)
In [3]: a
Out[3]: <__main__.ListA at 0x101cd0310>
In [4]: a.sum
Out[4]: <bound method ListA.sum of <__main__.ListA object at 0x101cd0310>>
In [5]: a.sum()
Out[5]: 9
In [6]: b = ListA(3,4)
In [7]: b.sum()
Out[7]: 7
In [8]: map(ListA.sum, [a, b])
Out[8]: [9, 7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment