List Methods
list.pop()
Removes and returns the element at the given index, defaulting to the last element. Negative indices count from the end. Unlike remove(), it selects by position rather than by equality. Empty lists and out-of-range indices raise IndexError. End removal suits stack operations; for frequent front removals consider collections.deque.
Formal Syntax & Structure
python syntaxpython
items.pop(index=-1, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| index | integer-like | Position to remove; defaults to -1. |
Return Value
object
The actual object removed from the list.
Working Example
Example Snippetpython
history = ["open", "edit", "save"]print(history.pop())print(history.pop(0))print(history)