Python Lists and Tuples

What Are Lists?

A list is a collection of items that you can change. Lists use square brackets [ ].

fruits = ["apple", "banana", "orange"]
print(fruits)
      

Accessing Items

print(fruits[0])   # apple
print(fruits[1])   # banana
      

Modifying a List

fruits[1] = "kiwi"
print(fruits)
      

Adding Items

fruits.append("mango")
      

Removing Items

fruits.remove("apple")
      

List Length

print(len(fruits))
      

Looping Through a List

for fruit in fruits:
    print(fruit)
      

What Are Tuples?

A tuple is like a list, but you cannot change it. Tuples use parentheses ( ).

colors = ("red", "green", "blue")
print(colors)
      

Accessing Tuple Items

print(colors[0])   # red
      

Tuples Are Immutable

This will cause an error:

colors[1] = "yellow"   # ❌ You cannot modify a tuple
      

When to Use What?

Combined Example

student = ["Kaloyan", 12, "Bulgaria"]  # list
position = (42.6977, 23.3219)          # tuple (coords)
      

What’s Next?

Next you’ll learn the basics of responsive web design and how websites adapt to different screen sizes.