In this article, you’ll see the Python list pop method. The pop method is used to remove an element from a list. The Python list pop method takes only one argument. If you don’t specify any index position in the argument then it will remove the last element. I highly recommend you get the “Python Crash Course Book” to learn Python.
Remove the 2nd Element
The index starts from 0 so the index of the 2nd element will be 1.
a = [8, 15, 16, 30, 24] a.pop(1) print(a)
Output:
[8, 16, 30, 24]
Remove the last Element
In the following example, I will not pass an argument so it will remove the last element.
b = [8, 15, 16, 30, 24] b.pop() print(b)
Output:
[8, 15, 16, 30]