ScanSkill

pop

pop() function or method is used in python list to remove and return the item at the specified index.

Syntax

list.pop(index)

Here,

  • index: Optional. Index of the item you want to delete. Default value is -1 (the last item in the list).

Examples

>>> list1 = [1, 2, 3]
>>> list1.pop()
3
>>> list1
[1, 2]
  • With index value passed
>>> list1 = [1, 2, 3]
>>> list1.pop(1)
2
>>> list1
[1, 3]

See also

remove() and append()