Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 3.1.1 (r311:74480, Sep 11 2009, 19:55:23)
- [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 0x7fb150ada910> <__main__.A object at 0x7fb150ada990>
- right eq <__main__.A object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada910>
- right eq <__main__.A object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada910>
- left eq <__main__.A object at 0x7fb150ada910> <__main__.A object at 0x7fb150ada990>
- False
- >>> A('left') == B('right')
- left eq <__main__.A object at 0x7fb150ada950> <__main__.B object at 0x7fb150ada910>
- right eq <__main__.B object at 0x7fb150ada910> <__main__.A object at 0x7fb150ada950>
- right eq <__main__.B object at 0x7fb150ada910> <__main__.A object at 0x7fb150ada950>
- left eq <__main__.A object at 0x7fb150ada950> <__main__.B object at 0x7fb150ada910>
- False
- >>> A('left') != A('right')
- left ne <__main__.A object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada950>
- right ne <__main__.A object at 0x7fb150ada950> <__main__.A object at 0x7fb150ada990>
- right ne <__main__.A object at 0x7fb150ada950> <__main__.A object at 0x7fb150ada990>
- left ne <__main__.A object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada950>
- True
- >>> A('left') != B('right')
- left ne <__main__.A object at 0x7fb150ada910> <__main__.B object at 0x7fb150ada990>
- right ne <__main__.B object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada910>
- right ne <__main__.B object at 0x7fb150ada990> <__main__.A object at 0x7fb150ada910>
- left ne <__main__.A object at 0x7fb150ada910> <__main__.B object at 0x7fb150ada990>
- True
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement