dunder_task_2.py 886 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Магические методы сравнения
  2. # __eq__ - ==
  3. # __ne__ - !=
  4. # __lt__ <
  5. # __le__ <=
  6. # __gt__ >
  7. # __ge__ >=
  8. class Rectangle:
  9. def __init__(self, a, b) -> None:
  10. self.a = a
  11. self.b = b
  12. @property
  13. def area(self):
  14. return self.a * self.b
  15. def __eq__(self, other):
  16. if isinstance(other, Rectangle):
  17. return self.a == other.a and self.b == other.b
  18. def __eq__(self, other):
  19. if isinstance(other, Rectangle):
  20. return self.area < other.area
  21. elif isinstance(other, (int, float)):
  22. return self.area < other
  23. def __le__(self, other):
  24. return self==other or self<other
  25. class Point:
  26. def __init__(self) -> None:
  27. pass
  28. def main():
  29. pass
  30. if __name__ == '__main__':
  31. main()