Python Tutorial #6: Data Structures — Lists, Dicts, Sets, Tuples

In the previous tutorial, we learned about functions. Now let’s learn about Python’s built-in data structures: lists, dictionaries, sets, and tuples. These are the tools you use every day in Python. By the end of this tutorial, you will know how to store, access, and transform collections of data. Lists A list is an ordered, mutable collection. You can add, remove, and change items. fruits = ["apple", "banana", "cherry"] print(fruits[0]) # apple — first item print(fruits[-1]) # cherry — last item print(len(fruits)) # 3 Adding Items fruits.append("date") # Add to end: ["apple", "banana", "cherry", "date"] fruits.insert(1, "avocado") # Insert at index 1: ["apple", "avocado", "banana", ...] fruits.extend(["fig", "grape"]) # Add multiple items to end Removing Items fruits.remove("banana") # Remove by value (first occurrence) last = fruits.pop() # Remove and return last item item = fruits.pop(0) # Remove and return item at index 0 List Slicing Slicing creates a new list from part of an existing list. The syntax is list[start:end:step]: ...

April 25, 2026 · 9 min