To concatenate two lists in Python:
(1) Using the + operator:
list_one = ["item1", "item2", "item3", ...]
list_two = ["item1", "item2", "item3", ...]
concatenated_list = list_one + list_two
print(concatenated_list)
(2) Using extend:
list_one = ["item1", "item2", "item3", ...]
list_two = ["item1", "item2", "item3", ...]
list_one.extend(list_two)
print(list_one)
The Steps
Step 1: Create two Lists
To begin with a simple example, create two lists that contain string values:
list_one = ["Banana", "Apple", "Mango", "Watermelon", "Pear"]
list_two = ["Blueberry", "Cherry", "Pineapple", "Papaya", "Coconut"]
print(list_one)
print(list_two)
Run the code in Python, and you’ll get these two lists:
['Banana', 'Apple', 'Mango', 'Watermelon', 'Pear']
['Blueberry', 'Cherry', 'Pineapple', 'Papaya', 'Coconut']
Step 2: Concatenate the two Python Lists using the + operator
You can use the + operator in order to concatenate the two lists:
list_one = ["Banana", "Apple", "Mango", "Watermelon", "Pear"]
list_two = ["Blueberry", "Cherry", "Pineapple", "Papaya", "Coconut"]
concatenated_list = list_one + list_two
print(concatenated_list)
As you can see, the two lists are now concatenated:
['Banana', 'Apple', 'Mango', 'Watermelon', 'Pear', 'Blueberry', 'Cherry', 'Pineapple', 'Papaya', 'Coconut']
Using Extend
Alternatively, you can use extend to concatenate the two lists:
list_one = ["Banana", "Apple", "Mango", "Watermelon", "Pear"]
list_two = ["Blueberry", "Cherry", "Pineapple", "Papaya", "Coconut"]
list_one.extend(list_two)
print(list_one)
The result:
['Banana', 'Apple', 'Mango', 'Watermelon', 'Pear', 'Blueberry', 'Cherry', 'Pineapple', 'Papaya', 'Coconut']
Concatenate More Than Two Lists
You can also use the + operator to concatenate multiple lists.
For example, to concatenate the following 4 lists:
list_one = ["Banana", "Apple", "Mango"]
list_two = ["Watermelon", "Pear"]
list_three = ["Blueberry", "Cherry"]
list_four = ["Pineapple", "Papaya", "Coconut"]
concatenated_list = list_one + list_two + list_three + list_four
print(concatenated_list)
The result:
['Banana', 'Apple', 'Mango', 'Watermelon', 'Pear', 'Blueberry', 'Cherry', 'Pineapple', 'Papaya', 'Coconut']
Check the following guide to learn more about creating a list in Python.