next up previous contents
Next: Repetition Up: List Operators Previous: List Operators   Contents


To combine the contents of two lists, use a plus sign (+) between the two lists to be concatenated. The result is a single list whose length is the total of the length of the two lists being combined, and which contains all of the elements of the first list followed by all of the elements of the second list.
>>> first = [7,9,'dog']
>>> second = ['cat',13,14,12]
>>> first + second
[7, 9, 'dog', 'cat', 13, 14, 12]
Alternatively, you can combine two lists with the expand method (Section 4.4).

Note that list concatenation only works when you're combining two lists. To add a scalar to the end of a list, you can either surround the scalar with square brackets ([ ]), or invoke the append method (Section 4.4).

Phil Spector 2003-11-12