Python List contains homogeneous elements enclosed in [ ] brackets. Concatenation is used to join the elements of one data structure with an end-to-end approach.
List concatenation helps to create one list with elements from different small lists by chaining them all together.
There are many ways for concatenating lists in Python.
In this article, we will learn six different techniques of how to concatenate lists in Python.
The article contains example code snippets along with the output for proper understanding.
We will use the following two lists in all the examples.
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
Table of Contents
1. Naive Method
The naive method traverses the second list with for loop and includes them in the first list. In this way, the first single list will have all the list elements included in both previous lists.
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
for i in list2:
list1.append(i)
print ("we have list concatenation with naive method : " + str(list1))
Output:

2. Plus ‘+’ operator
‘+’ is one of the simplest and most common methods of list concatenation. It uses the ‘+’ operator for the concatenation of lists. It is also called list concatenation operator.
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
list1 = list1 + list2
print ("we have list concatenation with ’+’ operator: " + str(list1))
Output:

3. Multiply ‘*’ operator
This method is confined to Python 3.6+ version. This operator is also called unpacking operator as it unpacks the item’s collection. Multiple lists can be concatenated with the help of the ‘*’ operator. The list generated with this operator can have multiple lists.
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
new_list = [*list1, * list2]
print ("we have list concatenation with ’*’ operator: " + str(new_list))
Output:

4. List Comprehension
List Comprehension concept is an alternative method of lists concatenation in Python. It is used to generate a list that is based on an existing list. The for loop is used to traverse the lists. Check the code for reference:
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
new_list = [ y for x in [list1, list2] for y in x ]
print ("we have list concatenation with list comprehension " + str(new_list))
Output:

5. Itertools.chain( )
Itertools. Chain() works with iterables like string, tuples, lists, etc., as parameters. The output is in linear sequence. Itertools.chain () constructs and returns iterator that is used to construct the chained list. This method is useful when we use a concatenated list for once only. Here is the code snippet:
import itertools
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
new_list = list(itertools.chain(list1, list2))
print ("we have list concatenation with itertools.chain(): " + str(new_list))
Output:

6. Extend( )
Extend( ) is a built-in list method that is for expanding the list. Lists extend this function in Python. It linearly extends the list. The first list gets expanded by the addition of the second list into it.
list1 = [ 2, 4, 6, 8, 10 ]
list2 = [ 2, 3, 5, 7, 9 ]
list1.extend(list2)
print ("we have list concatenation with extend() method: " + str(list1))
Output:

Conclusion:
All the above-mentioned methods are there to simplify the development process. In the article, we have covered the 6 distinct ways to concatenate a list in Python. I hope the example codes are helpful for the proper understanding of each technique.