python lists provide functions that will alter the list by inserting or removing values the pop function will remove and return the element at a specified index popping does not leave a gap in the list any elements to the right of the index are shifted one index to the left the index parameter is optional and if no argument is provided the last element in the list will be removed and returned automatically the length of the list is reduced by one after popping the insert function will insert a new value into the specified index the value currently at that index will be shifted to the right to make room for the new value the length of the list is increased by one after an insert both pop and insert are destructive functions like the append function and the extend operator they permanently modify the list the pop function will permanently remove and return the element at the specified index in the list in this case we popped the element at index zero and so a was removed from the list and returned leaving only the remaining elements B C D and E if no index is specified the last element is removed and returned in this case the letter e is removed from the list and returned the insert function can be used to insert elements at any valid index between 0o and length minus one inserting at the length of the list is the equivalent of Simply using the append function let's use the python interpreter to take a closer look at the pop and insert functions as before we'll start by creating a simple list the length of this list is five and it contains five elements 2 4 6 8 and 10 next I'm going to create a second reference to the same list we know that both C and A refer to the same list and we will use this to prove that the pop and insert functions make permanent changes to the list we will see those changes reflected both in a and C again because they both refer to the same list let's start by calling pop without any parameters we can see that the very last value in the list was returned by the pop function if you don't specify an index it is always going to remove and return the last value if we take a look at list a we can see that the 10 is no longer in the list it has permanently been removed and taking a look at list c will verify that as well the list has been permanently altered and its length has been reduced by one you can also use pop with an index in this case I've removed and returned the value at index zero that would be the two from the beginning of the list if we take a look at a it now no longer includes the two at the front of the list we can also see that each of the values that were to the right of two have now shifted one index to their left four used to be at index one it is now at index 0o six used to be at index 2 it is now at index one and so on and the length of the list has once again been reduced by one if you attempt to pop from an index that is out of range you will get an index error indicating that in this case index 100 is not a valid index in this list now let's take a look at the insert function in this case I've inserted a new value Fu at index zero in the list this means that each of the existing values had to be moved one in index to the right so the value 8 used to be at index 2 it is now at index 3 six was moved from index one to two and four was moved from index 0 to 1 this was done to make room for the new value to be inserted at the front of the list at index zero the length of the list is also now four it has increased by one after adding the new value calling the insert function with an index that is equal to the length of the list is the same as appending the value onto the end of the list in this case none of the existing values had to move to make room we just added the value bar to the very end of the list and the length of the list has increased by one so what happens if we try to insert into an index that is out of range in this case it works if the index is larger than the length of the list then the new value will be inserted at the end of the list exactly the same as if you insert at an index equal to the current length of the list because 100 is far too large the insert function does the best that it can and it just appends the value to the end