Q:

Concatenation of instance objects, should order matter?

I came across this curiosity after creating a simple class and instantiating it,
class A():
    def __init__(self,inp):
            self.id = inp
    def get_id(self):
            return self.id
    def __add__(self,other):
            return other + self.id

And the instantiation,
me = A('Matt')

Now when I try to use the overloaded method __add__ it works as expected,
me + ' test concatenation'   

but when I do it the other way around, 'test concatenation ' + me, I get 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'instance' objects

Why does the order of the arguments matter?

A:

Because the '+' notation is implicitly calling first.__add__(second).
Under the covers, when you have an expression like "hello" + " world", you are actually executing this: string.__add__(string). Hence, the __add__ method is that of the first argument, which is why the order matters.

