Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 4
    There is also __radd__ method that might be called sometimes (it is relevant for expressions that involve subclasses mostly). Commented Feb 27, 2010 at 19:55
  • 3
    In perspective: += is useful if memory and speed are important Commented Sep 26, 2012 at 7:20
  • 8
    Knowing that += actually extends a list, this explains why x = []; x = x + {} gives a TypeError while x = []; x += {} just returns []. Commented Aug 16, 2017 at 7:19
  • 2
    This answer is missing the (very important) fact that bar is a class variable. That, together with this answer, actually explain the observed behaviour. @AndiDog answer is better in that sense. Commented Aug 14, 2021 at 3:13