Write a class Example() such that it has a method that gives the difference between the size of strings when the '-' (subtraction) symbol is used between the two objects of the class. Additionally, implement a method that returns True if object 1 is greater than object 2 and False otherwise when the (>) (greater than) symbol is used. For example: obj1

Respuesta :

Answer:

Here the code is given as follows,

Explanation:

class Example:

   def _init_(self, val):

       self.val = val

   def _gt_(self, other):

       return self.val > other.val

   def _sub_(self,other):

       return abs(len(self.val) - len(other.val))

def main():

   obj1 = Example('this is a string')

   obj2 = Example('this is another one')

   print(obj1 > obj2)

   print(obj1 - obj2)

main()

Output:-

Ver imagen tallinn