Hi I was wondering if there is a way to do a symmetric operator override in Python. For example, let's say I have a class:
class A:
def __init__(self, value):
self.value = value
def __add__(self, other):
if isinstance(other, self.__class__):
return self.value + other.value
else:
return self.value + other
Then I can do:
a = A(1)
a + 1
But if I try:
1 + a
I get an error. Is there a way to override the operator add so that 1 + a will work?