Further adventures in array slicing.

7stud bbxx789_05ss at yahoo.com
Fri May 4 18:49:32 EDT 2007


> A second question is: When can you use += vs .append().
> Are the two always the same?

They are never the same unless you only add one item to the list.
append() will only increase the length of a list by 1.

la = [1,2]
lb = [3, 4, 5]
la += lb
print la

lc = [1,2]
lc.append(lb)
print lc

--output:--
[1, 2, 3, 4, 5]
[1, 2, [3, 4, 5]]


print la[2]
print lc[2]

--output:--
3
[3, 4, 5]




More information about the Python-list mailing list