Pop () method
PHP (N)
Delete an element from list
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 use the pop () method of list to delete:
>>> 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, the POP (2) is used to erase Paul:
>>> L.pop (2)
' Paul '
>>> Print L
[' Adam ', ' Lisa ', ' Bart ']
Python List Delete Element