Skip to main content
Engineering LibreTexts

8.4: List operations

The + operator concatenates lists:

 

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> c = a + b
>>> print(c)
[1, 2, 3, 4, 5, 6]

Similarly, the * operator repeats a list a given number of times:

 

>>> [0] * 4
[0, 0, 0, 0]
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]

The first example repeats four times. The second example repeats the list three times.