Lesson 5: Lists, Tuples, and Dictionaries

Python’s core data structures for storing and organizing information

Lists

Lists are ordered, changeable collections. They can store any type of data and can be modified after creation.

Creating Lists

fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4]
mixed = ["hello", 42, True]

Accessing List Items

print(fruits[0])   # apple
print(fruits[-1])  # cherry

Modifying Lists

fruits[1] = "blueberry"
fruits.append("orange")
fruits.remove("apple")

Useful List Methods

numbers = [3, 1, 4, 2]
numbers.sort()      # [1, 2, 3, 4]
numbers.reverse()   # [4, 3, 2, 1]

Tuples

Tuples are ordered but immutable collections. Once created, their values cannot be changed.

Creating Tuples

point = (10, 20)
colors = ("red", "green", "blue")

Accessing Tuple Items

print(point[0])   # 10

Why Use Tuples?

Dictionaries

Dictionaries store data as key‑value pairs. They are unordered, changeable, and extremely useful for structured data.

Creating Dictionaries

person = {
    "name": "Alice",
    "age": 30,
    "city": "Budapest"
}

Accessing Values

print(person["name"])       # Alice
print(person.get("age"))    # 30

Modifying Dictionaries

person["age"] = 31
person["job"] = "Developer"
del person["city"]

Dictionary Methods

print(person.keys())
print(person.values())
print(person.items())

Choosing the Right Data Structure

Next Steps

Now that you understand Python’s core data structures, you’re ready to learn how to control program flow using conditions in Lesson 6: Conditional Logic (if/elif/else).

← Back to Lesson Index