Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 2.6.2 (r262:71600, Sep 11 2009, 20:40:48)
- [GCC 4.3.2] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> from __future__ import print_function
- >>> class A(object):
- ... def __init__(self, name):
- ... self.name = name
- ... def __eq__(self, other):
- ... print(self.name, "eq", self, other)
- ... return NotImplemented
- ... def __ne__(self, other):
- ... print(self.name, "ne", self, other)
- ... return NotImplemented
- ... def __add__(self, other):
- ... print(self.name, "add", self, other)
- ... return NotImplemented
- ... def __radd__(self, other):
- ... print(self.name, "radd", self, other)
- ... return NotImplemented
- ...
- ... def __lt__(self, other):
- ... print(self.name, "lt", self, other)
- ... return NotImplemented
- ... def __gt__(self, other):
- ... print(self.name, "gt", self, other)
- ... return NotImplemented
- ...
- ...
- >>> class B(object):
- ... def __init__(self, name):
- ... self.name = name
- ... def __eq__(self, other):
- ... print(self.name, "eq", self, other)
- ... return NotImplemented
- ... def __ne__(self, other):
- ... print(self.name, "ne", self, other)
- ... return NotImplemented
- ... def __add__(self, other):
- ... print(self.name, "add", self, other)
- ... return NotImplemented
- ... def __radd__(self, other):
- ... print(self.name, "radd", self, other)
- ... return NotImplemented
- ...
- ... def __lt__(self, other):
- ... print(self.name, "lt", self, other)
- ... return NotImplemented
- ... def __gt__(self, other):
- ... print(self.name, "gt", self, other)
- ... return NotImplemented
- ...
- >>> A('left') == A('right')
- left eq <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right eq <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- left eq <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right eq <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- right eq <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- left eq <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- False
- >>> A('left') == B('right')
- left eq <__main__.A object at 0x7f7df0166410> <__main__.B object at 0x7f7df01663d0>
- right eq <__main__.B object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right eq <__main__.B object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- left eq <__main__.A object at 0x7f7df0166410> <__main__.B object at 0x7f7df01663d0>
- False
- >>> A('left') != A('right')
- left ne <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right ne <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- left ne <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right ne <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- right ne <__main__.A object at 0x7f7df0166410> <__main__.A object at 0x7f7df01663d0>
- left ne <__main__.A object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- True
- >>> A('left') != B('right')
- left ne <__main__.A object at 0x7f7df0166410> <__main__.B object at 0x7f7df01663d0>
- right ne <__main__.B object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- right ne <__main__.B object at 0x7f7df01663d0> <__main__.A object at 0x7f7df0166410>
- left ne <__main__.A object at 0x7f7df0166410> <__main__.B object at 0x7f7df01663d0>
- True
- >>>
Advertisement
Add Comment
Please, Sign In to add comment