To append a list to another list in Python, you can use the extend
method or the addition operator (+
).
In this example,
list1
and list2
with initial values.extend
method to append all elements of list2
to list1
.list1
to standard output.list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print('Updated list:', list1)
Updated list: [1, 2, 3, 4, 5, 6]
In this example,
list1
and list2
with initial values.+
) to concatenate list2
to list1
.list1
to standard output.list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1 += list2
print('Updated list:', list1)
Updated list: [1, 2, 3, 4, 5, 6]
In this tutorial, we learned How to Append a List to another List in Python language with well detailed examples.