Episode 5 of 29

Lists in Python

Learn about Python lists — creating, accessing, modifying, and iterating over ordered collections.

Lists are ordered, mutable collections that can hold any type of data.

Creating Lists

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

Accessing Elements

print(fruits[0])   # apple
print(fruits[-1])  # cherry
print(fruits[1:3]) # ["banana", "cherry"]

Modifying Lists

fruits.append("mango")
fruits.insert(1, "grape")
fruits.remove("banana")
fruits.sort()
fruits.reverse()