News for hackers. Stuff that matters.
Re:Facts and myths about Python names and values by rflrob on Sunday July 14, 2013 @02:16PM (#6041612)

    > 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

There are no comments on this comment yet.