Advertisement
BobStein

eq does not need ne in Python 3

Jun 8th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. D:\PyCharmProjects\fliki>python
  2. Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>> class LazyClass:
  5. ...     def __init__(self, name):
  6. ...         self.name = name
  7. ...
  8. ...     def __eq__(self, other):
  9. ...         return self.name[0] == other.name[0]
  10. ...
  11. >>> able = LazyClass('able')
  12. >>> alpha = LazyClass('alpha')
  13. >>>
  14. >>> print("able " + ("is"    if able == alpha else "is    NOT") + " equal to alpha")
  15. able is equal to alpha
  16. >>> print("able " + ("isn't" if able != alpha else "isn't NOT") + " equal to alpha")
  17. able isn't NOT equal to alpha
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement