Сравнение экземпляров классов в Python

Всем привет.

Помогите разобраться с магическими методами сравнения.

class Trailer_load_capacity:
         
    """ Trailer type class """

    def __init__(self, trailer_length=13.6, trailer_width=2.5, trailer_height=2.6):
        self.trailer_length = trailer_length
        self.trailer_width = trailer_width
        self.trailer_height = trailer_height


class Cargo:

     def __init__(self, cargo_length, cargo_width, cargo_height):
         self.cargo_length = cargo_length
         self.cargo_width = cargo_width
         self.cargo_height = cargo_height
         super().__init__(trailer_length=13.6, trailer_width=2.5, trailer_height=2.6)

     def __lt__(self, trailer_length=13.6):
         if self.cargo_length < trailer_length:
             return 'Your cargo is placed on a trailer'

     def __gt__(self, trailer_length=13.6):
         if self.cargo_length > trailer_length:
             return 'Your cargo is NOT placed on a trailer'

     def __le__(self, trailer_width=2.5):
         if self.cargo_width <= trailer_width:
             return 'The load is placed on a trailer'

     def __ge__(self, trailer_width=2.5):
         if self.cargo_width >= trailer_width:
             return 'Your cargo is NOT placed on a trailer'

     def __eq__(self, trailer_height=2.6):
         if self.cargo_height == trailer_height:
             return 'Load of suitable height'

И в примере моего кода, уместно ли наследования в классе Cargo, класса Trailer_load_capacity ? Как в таком случае сделать сравнение между экземпляров двух этих классов?


Ответы (0 шт):