File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1131,7 +1131,7 @@ a tuple points to.
11311131Under the covers, what this augmented assignment statement is doing is
11321132approximately this::
11331133
1134- >>> result = a_tuple[0].__iadd__(1)
1134+ >>> result = a_tuple[0] + 1
11351135 >>> a_tuple[0] = result
11361136 Traceback (most recent call last):
11371137 ...
@@ -1154,16 +1154,19 @@ that even though there was an error, the append worked::
11541154 >>> a_tuple[0]
11551155 ['foo', 'item']
11561156
1157- To see why this happens, you need to know that for lists, ``__iadd__ `` is equivalent
1158- to calling ``extend `` on the list and returning the list. That's why we say
1159- that for lists, ``+= `` is a "shorthand" for ``list.extend ``::
1157+ To see why this happens, you need to know that (a) if an object implements an
1158+ ``__iadd__ `` magic method, it gets called when the ``+= `` augmented assignment
1159+ is executed, and its return value is what gets used in the assignment statement;
1160+ and (b) for lists, ``__iadd__ `` is equivalent to calling ``extend `` on the list
1161+ and returning the list. That's why we say that for lists, ``+= `` is a
1162+ "shorthand" for ``list.extend ``::
11601163
11611164 >>> a_list = []
11621165 >>> a_list += [1]
11631166 >>> a_list
11641167 [1]
11651168
1166- is equivalent to::
1169+ This is equivalent to::
11671170
11681171 >>> result = a_list.__iadd__([1])
11691172 >>> a_list = result
You can’t perform that action at this time.
0 commit comments