Python provides several built-in data structures, and it also allows you to create custom ones. These are mainly divided into
primitive and non-primitive (collection) data structures.
1. Primitive Data Structures
These are the most basic types:
int → integers (10, -3)
float → floating-point numbers (3.14, -2.5)
complex → complex numbers (3+4j)
bool → boolean values (True, False)
str → strings ("hello", 'Python')
2. Non-Primitive (Collections) Data Structures
These are used to store multiple values.
a. List
Ordered, mutable, allows duplicates.
Example:
fruits = ["apple", "banana", "cherry"]
b. Tuple
Ordered, immutable, allows duplicates.
Example:
coordinates = (10, 20)
c. Set
Unordered, mutable, does not allow duplicates.
Example:
unique_numbers = {1, 2, 3, 3}
# {1, 2, 3}
d. Dictionary (dict)
Unordered (insertion-ordered since Python 3.7), mutable, stores key–value pairs.
Example:
student = {"name": "Alice", "age": 20}
3. Specialized Data Structures (from collections module)
deque → double-ended queue
Counter → frequency counter
OrderedDict → dict with ordering preserved (now built-in by default in Python 3.7+)
defaultdict → dict with default values for missing keys
namedtuple → tuple with named fields
4. User-Defined Data Structures
You can also implement:
Stack (using list or deque)
Queue (using deque or queue.Queue)
Linked List
Tree
Graph
Hash Table (dict is already a hash table internally)
In short:
Built-in collections → list, tuple,
set, dict
Extended collections → deque, Counter,
defaultdict, etc.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Python provides several built-in data structures, and it also allows you to create custom ones. These are mainly divided into primitive and non-primitive (collection) data structures.
1. Primitive Data Structures
These are the most basic types:
10,-3)3.14,-2.5)3+4j)True,False)"hello",'Python')2. Non-Primitive (Collections) Data Structures
These are used to store multiple values.
a. List
Ordered, mutable, allows duplicates.
Example:
b. Tuple
Ordered, immutable, allows duplicates.
Example:
c. Set
Unordered, mutable, does not allow duplicates.
Example:
d. Dictionary (dict)
Unordered (insertion-ordered since Python 3.7), mutable, stores key–value pairs.
Example:
3. Specialized Data Structures (from
collectionsmodule)4. User-Defined Data Structures
You can also implement:
deque)dequeorqueue.Queue)In short:
list,tuple,set,dictdeque,Counter,defaultdict, etc.