Hello everyone!
I’m currently on: Learn Python 3 > Lists > Working with Lists in Python > Adding by Index: insert
Learn Python 3 | Codecademy
So here is my question:
I’m doing this exercise and decided to start adding a couple of elements using different indexes. For “Strawberries”, I tried to insert it in index -1, which to my understanding is supposed to insert the element to the end of my list, but it’s inserted in front of “Chocolate Milk”.
front_display_list = [“Mango”, “Filet Mignon”, “Chocolate Milk”]
front_display_list.insert(0, “Pineapple”)
front_display_list.insert(-1, “Strawberries”)
Outputs:
[‘Pineapple’, ‘Mango’, ‘Filet Mignon’, ‘Strawberries’, ‘Chocolate Milk’]
My best guess is that if I wanted to put it at the end of the list, I would use “append” instead of insert?