Learn Before
Concept

Stack

A stack is a data structure that stores items in a "last in, first out" (LIFO) manner. New elements are added to and removed from the end of a stack. When an item is added to a stack, the operation is known as a "push". When an item is removed from a stack, the operation is known as a "pop".

A simple stack can easily be implemented in Python using the List built-in data structure.

stack = [] # empty stack using the List structure. stack.append(23) stack.append(98) stack.append(5) element1 = stack.pop() # pops 5 from the stack and sets the value of element1 to 5 element2 = stack.pop() # pops 98 from the stack and sets the value of element2 to 98

0

1

Updated 2025-10-06

Tags

Python Programming Language

Data Science

Computing Sciences

Foundations of Large Language Models Course