May 2017
Intermediate to advanced
280 pages
6h 2m
English
If you want to see a removed item, you can use the pop () method. The syntax for the method is given as follows:
list.pop()
The pop () method removes and returns the last item from the list.
Let's take the example of the famous TV series, GoT:
>>> GoT = ["Tyrion","Sansa", "Arya","Joffrey","Ned-Stark"]>>> GoT.pop()'Ned-Stark'>>> GoT.pop()'Joffrey'>>> GoT['Tyrion', 'Sansa', 'Arya']>>>
In the preceding example, you can see that the pop () method returns the removed item. You can also remove any item based on the index. See the following example:
>>> GoT = ["Tyrion","Sansa", "Arya","Catelyn","Joffrey","Ned-Stark"]>>> GoT = ["Tyrion","Sansa", "Arya","Catelyn","Joffrey","Ned-Stark"]>>> GoT.pop(3)'Catelyn'>>> GoT['Tyrion', 'Sansa', 'Arya', ...
Read now
Unlock full access