Paul's classmates had to turn away a few days ago, so how do we remove Paul from the existing list?
If Paul's classmates were in the last one, we could delete them using the list pop() method:
>>> L = [' Adam ', ' Lisa ', ' Bart ', ' Paul ']>>> L.pop () ' Paul ' >>> print l[' Adam ', ' Lisa ', ' Bart ']
The pop () method always deletes the last element of the list, and it returns the element, so we print out ' Paul ' after we execute L.pop ().
What if Paul's classmates aren't the last one? For example, Paul is ranked third:
>>> L = [' Adam ', ' Lisa ', ' Paul ', ' Bart ']
To kick Paul out of the list, we have to locate Paul's position first. Since Paul's index is 2, use Paul to erase it pop(2) :
>>> L.pop (2) ' Paul ' >>> print l[' Adam ', ' Lisa ', ' Bart '
The above content transferred from MU class net, only for individual study!
Python deletes elements from list