Lists and Tuples - Working with Collections
Understand Python's fundamental collection data types

📚 Resources for This Lesson
Lists
Lists are mutable collections of items.
# Creating a list
fruits = ["apple", "banana", "cherry"]
# Accessing elements
print(fruits[0]) # apple
# Adding elements
fruits.append("date")
# Removing elements
fruits.remove("banana")
# List comprehension
numbers = [x**2 for x in range(5)]
Tuples
Tuples are immutable collections of items.
# Creating a tuple
coordinates = (10, 20)
# Accessing elements
x, y = coordinates
# Tuples are immutable
# coordinates[0] = 30 # This will raise an error
Common Methods
List Methods
append()- Add itemextend()- Add multiple itemsinsert()- Insert at specific positionremove()- Remove by valuepop()- Remove by index
Useful Functions
len()- Get lengthsorted()- Sort itemsreversed()- Reverse ordersum()- Sum numeric items