We add a value to a specific index with insert()
. By coding insert(0, "lemon")
, we'll add the value to the start of the list.
shopping = ["kiwis", "peas"]
shopping.insert(0, "lemon")
print(shopping)
The index we want to insert the value at comes first, then the value. insert(1, "chocolate")
adds a value in the second position.
shopping = ["kiwis", "peas"]
shopping.insert(0, "lemon")
shopping.insert(1, "chocolate")
print(shopping)