PythonListpop

Removes and returns the element at the given index (default: last).

Syntax

list.pop(i?)

Example

Enter values below to update the example in real time.

stack
pop
print
stack = [1, 2, 3, 4]
last = stack.pop()
print(last)   # 4
print(stack)  # [1, 2, 3]

second = stack.pop(1)
print(second)  # 2