To concatenate two lists in Python, you can use the +
operator or the extend
method.
In this example,
list1
and list2
with initial values.+
operator to concatenate list2
to list1
.list1 = [1, 2, 3]
list2 = [4, 5, 6]
concatenated_list = list1 + list2
print('Concatenated list:', concatenated_list)
Concatenated list: [1, 2, 3, 4, 5, 6]
In this example,
list1
and list2
with initial values.extend
method to append all elements of list2
to list1
.list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print('Concatenated list:', list1)
Concatenated list: [1, 2, 3, 4, 5, 6]
In this tutorial, we learned How to Concatenate Two Lists in Python language with well detailed examples.