my_list = ['a','b'] my_list.append('c') print(my_list) # ['a','b','c'] other_list = [1,2] my_list.append(other_list) print(my_list) # ['a','b','c',[1,2]] my_list.extend(other_list) print(my_list) # ['a','b','c',[1,2],1,2]
Here is what the above code is Doing:
1. We create a list called my_list and add two elements to it.
2. We create another list called other_list and add two elements to it.
3. We use the append method to add the other_list to my_list.
4. We use the extend method to add the elements of other_list to my_list.
The difference between append and extend is that append adds the other_list as a single element to my_list, while extend adds the elements of other_list to my_list.