Alan Franzoni wrote: > Yeah, that's right, it could have semantic differences, but that > shouldn't be the case anyway. I mean, if I don't define an __iadd__ > method, writing > > a += n > > or > > a = a + n > > is just the same, right? > > So, if I bother to define an __iadd__ method, I should make sure it > works just the same, or I would introduce a very strange and > hard-to-understand behaviour.
As you've seen, that's not the case. The *whole point* of having __iadd__ is to perform an *in-place* add i.e. mutate the object you're assigning to. So it's the behaviour of *immutable* objects that is the exception. The other semantics of immutable objects cover that though - you should never rely on whether two equal immutable objects (like integers) are the same or different objects. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list