Stack is empty — push a value
AlgoPlus//structures / stack
Read the theory

Stack · LIFO

Last-In-First-Out — push and pop happen at the top.

Stability
In-Place
Space Complexity
Avg Time
Legend
Push
Pop
Top / peek
AI Tutor Workspace
In a nutshell
A stack is a pile where you only ever touch the top: you push a value on, pop the top one off, or peek at it without removing it. That makes it Last-In-First-Out — the most recent thing added is the first to leave, like a stack of plates. Each operation is instant, and this simple rule is exactly what powers undo buttons, the browser back button, and the call stack that tracks running functions.
Ready
Press play to begin the cinematic walkthrough.
Like a pile of plates — you add and take only from the top, so the last thing in is the first thing out.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Stack · LIFO.
Code Simulator
1
class Stack:
2
    def __init__(self):
3
        self.items = []
4
    def push(self, item):
5
        self.items.append(item)  # Push
6
    def pop(self):
7
        if not self.is_empty():
8
            return self.items.pop()  # Pop
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.