The pop Method in Python: Removing an Element from a List

Returns the element at the specified position and removes it from the list.

pop([i])

  • i -- index of the element to remove from the list. If not specified, the last element is removed.
my_list = [1, 3, "eggs", "spam"]
my_list.pop(1)  # Returns 3
my_list.pop()  # Returns "spam"

To remove an element from a list without returning it, use the remove() method.