Is it possible in python to overload operators for a class so that the order of variables in using the operator does not matter?
For example, is there a way to do the following, without getting a TypeError?
class A:
def __init__(self, x: int):
self.x = x
def __add__(self, other: int):
return self.x + other
a = A(1) + 4 # a = 5
# what about this:
a = 4 + A(1)