Wednesday, August 05, 2009

trac源代码阅读 - 5 python operators

__add__ == +
>>> class a(object):
... def __or__(self, t):
... return id(t)
... def __add__(self, t):
... return id(t)
...
>>> c = a()
>>> a()+c
13041552
>>> id(c)
13041552




__sub__ == -
>>> class a(object):
... def __or__(self, t):
... return id(t)
... def __add__(self, t):
... return id(t)
... def __sub__(self, t):
... return id(t)
...
>>> c = a()
>>> a()-c
13041552
>>> id(c)
13041552

why? will continue in next post.

No comments: