xxxxxxxxxx
# list.append(x): add an item to the end
list_1 = ['A', 'B', 'C']
list_1.append('D') # -> ["A", "B", "C", "D"]
# list.insert(i, x): insert an item at a given position
list_2 = ['A', 'B', 'D']
list_2.insert(2, 'C') # -> ["A", "B", "C", "D"]
# list.extend(iterable): appending all items from an iterable
list_3 = ['A', 'B', 'C']
list_4 = ['D', 'E', 'F']
list_3.extend(list_4) # -> ['A', 'B', 'C', 'D', 'E', 'F']
xxxxxxxxxx
my_list = []
item1 = "test1"
my_list.append(item1)
print(my_list)
# prints the list ["test1"]
xxxxxxxxxx
my_input = ['Engineering', 'Medical']
my_input.append('Science')
print(my_input)
xxxxxxxxxx
MyList = ["apple", "banana", "orange"]
MyList.append("raspberry")
# MyList is now [apple, banana, orange, raspberry]
xxxxxxxxxx
months = ['January', 'February', 'March']
months.append('April')
print(months)
xxxxxxxxxx
lst = ["f", "o", "o", "b", "a","r"]
lst.append("b")
print(lst) # ["f", "o", "o", "b", "a", "r", "b"]
xxxxxxxxxx
my_list=[0,1,2,3]
new_element=700
new_list=[4,5,6]
#if you want add at the end of list:
my_list.append(new_element)
#if you want add a list merge two lists:
my_list.extend(new_list)
#if you want to add element in a specific index
my_list.insert(index , new_element)