title: Is there a way to overload += in python?
body: <p>I know about the <code>__add__</code> method to override plus, but when I use that to override +=, I end up with one of two problems:</p>
  
  <p>(1) if <code>__add__</code> mutates self, then </p>
  
  <pre><code>z = x + y
  </code></pre>
  
  <p>will mutate x when I don't really want x to be mutated there.</p>
  
  <p>(2) if <code>__add__</code> returns a new object, then</p>
  
  <pre><code>tmp = z
  z += x
  z += y
  tmp += w
  return z
  </code></pre>
  
  <p>will return something without w since z and tmp point to different objects after <code>z += x</code> is executed.</p>
  
  <p>I can make some sort of <code>.append()</code> method, but I'd prefer to overload <code>+=</code> if it is possible.</p>