Skip to content

Using Lists as Stacks

append and pop

stack = [3, 4, 5]
stack.append(6)
stack.append(7)
print(stack)
# [3, 4, 5, 6, 7]
x = stack.pop()
print(x)
# 7
print(stack)
# [3, 4, 5, 6]