4 ms·
> list += seq uses the __iadd__ method, which almost certainly uses the exact same mechanism as the list.extend() method. When this method isn't defined (c.f.
by rflrob 13y ago
> list += seq
uses the __iadd__ method, which almost certainly uses the exact same mechanism as the list.extend() method. When this method isn't defined (c.f. the Counter class from the collections module), a += b works like a = a + b.
> from collections import Counter
> c = Counter()
> c_old = c
> d = Counter()
> c += d
> '__iadd__' in dir(c)
False
> c_old is c
False
> a = []
> a_old = a
> b = []
> a += b
> '__iadd__' in dir(a)
True
> a_old is a
True