commonly used built-in data structures are:
- Lists
- Dictionaries
- Tuples
- Sets
Let’s look at each one with examples.
📝 If You Want to Practice the Code
If you plan to practice the Python code mentioned within this blog post, you’ll need a working Python environment. You can execute the commands in one of the following ways (choose only one option):
- From a Python prompt in your terminal or command line – see Getting Started with Python and Virtual Environment in Python and How to Set One Up
- Using Miniconda and Jupyter Notebook – see How to Install and Set Up Miniconda and Install Jupytor Notebook Windows, How to Install and Set Up Miniconda on MacOS, How to Install and Set Up Miniconda on Linux (Ubuntu), and Getting Started with Jupyter Notebooks.
- On Google Colab (browser-based, no installation required) – see Getting Started with Google Colab.
- Through VS Code – see Setting Up VS Code for Python Development.
👉 Choose whichever environment you’re most comfortable with. If you haven’t set up Python yet, start with one of the installation posts before trying the examples here.
🔹 Lists
A list is an ordered collection of items. You can store numbers, strings, or even other lists. Lists are mutable, meaning you can change them after creation.
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
fruits.append("mango") # add item
print(fruits) # ['apple', 'banana', 'cherry', 'mango']
fruits[1] = "blueberry" # update item
print(fruits) # ['apple', 'blueberry', 'cherry', 'mango']
🔹 Dictionaries
A dictionary stores data as key–value pairs. Keys are unique, and values can be anything.
student = {"name": "Alice", "age": 20, "grade": "A"}
print(student["name"]) # Alice
student["age"] = 21 # update value
student["city"] = "Toronto" # add new key-value
print(student)
👉 Output: {'name': 'Alice', 'age': 21, 'grade': 'A', 'city': 'Toronto'}
🔹 Tuples
A tuple is like a list, but it is immutable (cannot be changed once created). Tuples are often used for fixed collections of items.
coordinates = (10, 20)
print(coordinates[0]) # 10
# coordinates[0] = 15 # ❌ Error: Tuples cannot be changed
🔹 Sets
A set is an unordered collection of unique items. Sets are useful when you want to avoid duplicates.
numbers = {1, 2, 3, 3, 4}
print(numbers) # {1, 2, 3, 4}
numbers.add(5)
print(numbers) # {1, 2, 3, 4, 5}
numbers.remove(2)
print(numbers) # {1, 3, 4, 5}
📝 Mini Task
Try this small exercise combining all four:
# Create a list of students
students = ["Alice", "Bob", "Charlie"]
# Convert it into a dictionary with grades
grades = {"Alice": "A", "Bob": "B", "Charlie": "C"}
# Store their ages in a tuple
ages = (20, 21, 19)
# Create a set of unique courses
courses = {"Math", "Science", "Math"} # 'Math' will appear only once
print(students)
print(grades)
print(ages)
print(courses)
✅ Summary
- Lists → ordered, changeable collections.
- Dictionaries → key–value pairs for structured data.
- Tuples → ordered but unchangeable collections.
- Sets → unordered collections with unique items.
Understanding these four will give you the foundation to organize data effectively in Python.