Skip to content
Python Built-in Data Structures: Lists, Sets, Dictionaries, and Tuples
Fundamentals 4 min read

Python Built-in Data Structures: Lists, Sets, Dictionaries, and Tuples

This article introduces Python's core built‑in data structures—lists, sets, dictionaries, and tuples—explaining their characteristics, typical use cases, and providing clear code examples for creation, modification, and access.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle

Lists are ordered, mutable collections that allow duplicate elements. They are suitable when element order matters and the collection needs to be modified, such as storing a sequence of numbers or names.

list = [1, 2, 3, 4, 5]  # create a list
list.append(6)  # add an element
print(list)  # output the list

Sets are unordered, mutable collections that automatically enforce uniqueness, making them ideal for deduplication and set operations like union, intersection, and difference.

set = {1, 2, 2}  # duplicate values are removed
set.add(4)  # add an element
print(set)  # output: {1, 2, 4}

Dictionaries store key‑value pairs; they are mutable and, since Python 3.6, preserve insertion order. Keys are unique, enabling fast lookup of values by key, useful for mappings such as user profiles or configuration data.

dict = {"name": "Alice", "age": 25}
dict["age"] = 26  # modify a value
print(dict["age"])  # output: 26

Tuples are ordered, immutable collections that may contain duplicate elements. They are used when a fixed sequence of items should not change, such as coordinates or as keys in dictionaries.

tuple = (1, 2, 3)  # immutable tuple
print(tuple)  # output: (1, 2, 3)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

data structuresprogramming fundamentalsListdictionarytupleset
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.