How to Add Two List in Python
In this article we will see how to add two lists in Python. If you are looking for “how to merge two list in python”, this article will help you for the same.
Method 1: Using + operator
list1 = [1, 2, 3] list2 = [1, 4, 9] list3 = list1 + list2 print("The concatenated list :"+ str(list3))
Output:
The concatenated list :[1, 2, 3, 1, 4, 9]
Method 2: Using list comprehension
list1 = [1, 2, 3] list2 = [1, 4, 9] list3 = [j for i in [list1, list2] for j in i] print("The concatenated list :"+ str(list3))
Output:
The concatenated list :[1, 2, 3, 1, 4, 9]
Method 3: Using extend()
list1 = [1, 2, 3] list2 = [1, 4, 9] list1.extend(list2) print("The concatenated list :"+ str(list1))
Output:
The concatenated list :[1, 2, 3, 1, 4, 9]
Subscribe
Login
Please login to comment
0 Discussion