How to Concatenate Two Lists in Python?
You can concatenate two lists in Python by using the "+" operator or by using the extend() method.
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]
Using the extend() method:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
# Output: [1, 2, 3, 4, 5, 6]
Note that using the "+" operator creates a new list, whereas using the extend() method modifies the original list.