How to Concatenate Two List Variables in Python?

In this tutorial, learn how to concatenate two list variables in Python. The short answer is: use plus (+) operator or extend() to combine the elements of list variable using Python.

Concatenation is the process of combining two elements. The concatenation result out the combine two or more list using Python. However, here, you will get examples to concatenate only two lists variables in Python.

There are two methods by which you combine elements of two list variables. The first is the plus(+) operator and the second is the extend in Python. Let’s start describing each method one by one.

Using Plus(+) Operator to Concatenate Two List Variables in Python

If you want to concatenate two list variables, you have to use the plus(+). You have to use the below-given example to combine or join the two list elements. It stores the combined list elements to the third variable.

After a combination of the list elements in the third variable, you can print it using the print statement.

Output

[‘Dhoni’, ‘Virat’, ‘Rohit’, ‘Yuvraj’, ‘Chris Gayle’, ‘Carlos Brathwaite’]

The above example showing the output with the combined elements of the list variable.

However, if you want to use the extend method and combine the list elements. You have to read further to learn this method.

How to Combine the Variables Using extend() in Python

If you want to concatenate the two list elements, you have to use the extend() in Python. The extend method combines the elements of two list variables.

The above example combines the two list variable and stores them in the third element. However, if you want to use the extend method.

You cannot store the resulted combined list to the third element. The combined list will be stored in the previously existed list. You can store all the elements to the first or the second list variable.

Output

[‘Dhoni’, ‘Virat’, ‘Rohit’, ‘Yuvraj’, ‘Chris Gayle’, ‘Carlos Brathwaite’]

The above example prints all the elements in the output. It stores all the elements of the two list variables in the first list variable. After that, it prints the result using the print statement.

You may also like to read

I hope you like this tutorial on how to combine elements of two list variables.

You may also like to read