5 ms·
It's not ENTIRELY obvious. For example, tup[0].extend([1]) would work fine, and the behaviour of __iadd__() seems like it should be the same as extend(). In fac
by rix0r 12y ago
It's not ENTIRELY obvious. For example, tup[0].extend([1]) would work fine, and the behaviour of __iadd__() seems like it should be the same as extend(). In fact, the reference[1] has the following thing to say:
> For instance, to execute the statement x += y, where x is an instance of a class that has an __iadd__() method, x.__iadd__(y) is called.
However, this is patently not true, apparently:
tup = ([],)
tup[0].__iadd__([1]) # Works
print tup
tup = ([],)
tup[0] += [1] # TypeError
print tup
[1] https://docs.python.org/2/reference/datamodel.html#emulating-numeric-types https://docs.python.org/2/reference/datamodel.html#emulating...