1. Consider the following code:
class MyOperand:
def __init__(self, op):
self.op1 = op
def __add__(self, otherOperand):
return ‘Result:’, self.op1 + otherOperand.op1
x = MyOperand(4)
y = MyOperand(5)
print(x+y)
x = MyOperand(“H”)
y = MyOperand(“i”)
print(x+y)
In the above code, when two instances of the class MyOperandi.e. x and y are added with
the + operator we see that the built-in function __add__ iscalled. Here, the + operator was
overloaded to add two numbers or concatenate two strings with anote that reads ‘Result’.
1- Include the __sub__ function in the above code and test itwith numbers, strings, and
lists. Explain the results.
i need the answer in python code please?
Expert Answer
An answer will be send
PayPal Gateway not configured
PayPal Gateway not configured