list[] = var => list.append(var) (phpstyle)

Skip Montanaro skip at pobox.com
Mon Jul 16 16:31:29 EDT 2001


    >>> l1 = [1]
    >>> l2 = [2]
    >>> l1 += l2
    >>> l1
    [1, 2]

    vs.

    >>> l2.append(l1)
    >>> l2
    [2, [1]]

Note that list += another_list is defined as

    list.extend(another_list)

which does what you'd expect:

    >>> l1 = [1]
    >>> l2 = [2]
    >>> l1.extend(l2)
    >>> l1
    [1, 2]

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list