1# Basic syntax:
2first_list.append(second_list) # Append adds the the second_list as an
3# element to the first_list
4first_list.extend(second_list) # Extend combines the elements of the
5# first_list and the second_list
6
7# Note, both append and extend modify the first_list in place
8
9# Example usage for append:
10first_list = [1, 2, 3, 4, 5]
11second_list = [6, 7, 8, 9]
12first_list.append(second_list)
13print(first_list)
14--> [1, 2, 3, 4, 5, [6, 7, 8, 9]]
15
16# Example usage for extend:
17first_list = [1, 2, 3, 4, 5]
18second_list = [6, 7, 8, 9]
19first_list.extend(second_list)
20print(first_list)
21--> [1, 2, 3, 4, 5, 6, 7, 8, 9]
1a = [1, 2, 3]
2b = [4, 5]
3
4# method 1:
5c = a + b # forms a new list with all elements
6print(c) # [1, 2, 3, 4, 5]
7
8# method 2:
9a.extend(b) # adds the elements of b into list a
10print(a) # [1, 2, 3, 4, 5]
1list1 = ["a", "b" , "c"]
2list2 = [1, 2, 3]
3
4list1.extend(list2)
5print(list1)
6
1listone = [1,2,3]
2listtwo = [4,5,6]
3mergedlist = []
4mergedlist.extend(listone)
5mergedlist.extend(listtwo)