In Python, you can concatenate two lists using the + operator or the extend() method. Here's how you can use each of these methods:
Method 1: Using the + operator
list1 = [1, 2, 3]
list2 = [4, 5, 6]
concatenated_list = list1 + list2
print(concatenated_list)
Output:
[1, 2, 3, 4, 5, 6]
Method 2: Using the extend() method
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
Output:
[1, 2, 3, 4, 5, 6]
Both of these methods will concatenate the two lists and produce the same result.
Comments (0)