← Go Back

How to Merge Two Lists or Tuples

Using the addition operator.

>>> [1, 2] + [3, 4]
[1, 2, 3, 4]
>>> (1, 2) + (3, 4)
(1, 2, 3, 4)

Or, although less common, using the unpacking syntax with the * operator:

>>> a = [3, 4]
>>> [1, 2, *a]
[1, 2, 3, 4]

Since lists are mutable, you can also use the extend() method to add elements of another list to the end of the current one.

>>> a = [1, 2]
>>> b = [3, 4]
>>> a.extend(b)
>>> a
[1, 2, 3, 4]


lists tuples


🐍 You might also find interesting: