In Python, lists are one of the most versatile and commonly used data structures. Whether you're storing numbers, strings, or even other lists, Python lists make it easy to organize and manipulate data.
In this post, we’ll explore:
What lists are
How to create and access them
Common list methods you’ll use every day
A list is an ordered, mutable collection of items. You can think of it like a container that holds a sequence of elements.
fruits = ["apple", "banana", "cherry"]
Lists are defined using square brackets []
Items are separated by commas
Lists can contain any data type — even other lists!
You can access elements using indexing:
print(fruits[0]) # Output: apple
Python uses zero-based indexing, so the first element is at index 0.
You can also use negative indexing:
print(fruits[-1]) # Output: cherry
for fruit in fruits:
print(fruit)
This will print each item in the list one by one.
Here are some of the most useful list methods:
Adds an item to the end of the list.
fruits.append("orange")
Inserts an item at a specific index.
fruits.insert(1, "mango")
Removes the first occurrence of a value.
fruits.remove("banana")
Removes and returns an item at a given index (default is the last item).
last_item = fruits.pop()
Sorts the list in ascending order (in-place).
numbers = [3, 1, 4, 2]
numbers.sort()
Reverses the order of the list (in-place).
fruits.reverse()
Returns the number of items in the list.
print(len(fruits))
You can change list items directly:
fruits[0] = "grape"
This mutability makes lists powerful — but also something to be careful with when copying or sharing data.
Lists are a foundational part of Python programming. Mastering them — and their built-in methods — will make your code cleaner, faster, and more efficient.
Next up in the series: List Comprehension