list_1 = [1, 2]
list_2 = [3, 4]
result = list_1 + list_2
print(result)
The simplest method to join two lists is by using the + operator and placing the + keyword between lists that you want to concatenate.
In the above code snippet:
Join three lists using + operator
list_1 = ['Apple', 'Banana']
list_2 = ['Orange']
list_3 = ['papaya']
result = list_1 + list_2 + list_3
print(result)
Output
['Apple', 'Banana', 'Orange', 'papaya']
You can join two lists using extend() function too. The basic syntax to join two lists using extend() function will be:
List1.extend(List2)
Code Example
list_1 = ['Microsoft', 'Apple']
list_2 = ['Tesla']
list_1.extend(list_2)
print(list_1)
Output
['Microsoft', 'Apple', 'Tesla']
list_1 = ['Microsoft', 'Apple']
list_2 = ['Tesla', 'Devsheet', 'SpaceX']
#Join List_2 in List_1
for item in list_2:
list_1.append(item)
print(list_1)
# -> ['Microsoft', 'Apple', 'Tesla', 'Devsheet', 'SpaceX']
0 Comments