To join lists in Python, you can use the `+` operator or the `extend` method to combine multiple lists into a single list.
In this example,
list1
and list2
with integer values.+
operator to join list1
and list2
into a new list named joined_list
.list1 = [1, 2, 3]
list2 = [4, 5, 6]
joined_list = list1 + list2
print(f"Joined List: {joined_list}")
Joined List: [1, 2, 3, 4, 5, 6]
In this example,
listA
, listB
, and listC
with string values.result_list
and use the extend
method to add all elements from listA
, listB
, and listC
to result_list
.listA = ["apple", "banana"]
listB = ["cherry", "date"]
listC = ["fig", "grape"]
result_list = []
result_list.extend(listA)
result_list.extend(listB)
result_list.extend(listC)
print(f"Joined List: {result_list}")
Joined List: ['apple', 'banana', 'cherry', 'date', 'fig', 'grape']
In this tutorial, we learned How to Join Lists in Python language with well detailed examples.