Python Lists Explained with 6 Beginner Examples
Last Updated: August 2025
Ever wanted to store multiple things — like your top 5 snacks — in one place? That’s exactly what Python lists do. Think of them like boxes that can hold anything: numbers, text, even other boxes!
What’s a List in Python?
Lists are ordered collections. You can change them, grow them, shrink them, sort them — super flexible. And they’re written using square brackets like [ ]
.
Example 1: Creating a List
fruits = ["apple", "banana", "mango"]
print(fruits)
🔹This creates a list of fruits. Pretty straightforward, right?
Example 2: Accessing Items
print(fruits[0]) # apple
print(fruits[-1]) # mango
🔹Use indexes to grab specific items. Index 0
is the first item, and -1
gives you the last one.
Example 3: Adding to the List
fruits.append("orange")
print(fruits)
🔹append()
sticks something at the end. There’s also insert()
if you want to sneak it in somewhere specific.
Example 4: Removing Items
fruits.remove("banana")
print(fruits)
🔹Say goodbye to “banana”! You can also use pop()
or del
depending on what you're trying to do.
Example 5: Looping Through a List
for fruit in fruits:
print(fruit)
🔹This will print each fruit one at a time. Perfect for when you want to do something with every item.
Example 6: Sorting the List
numbers = [4, 1, 9, 3]
numbers.sort()
print(numbers) # [1, 3, 4, 9]
🔹sort()
organizes things in-place. Use sorted()
if you don’t want to mess with the original list.
Why Should You Learn Lists?
- They're everywhere — in websites, games, apps, data science… you name it.
- They keep your code clean and organized instead of creating 100 separate variables.
- You’ll need lists in *literally* every real-world Python project.
Ready to Practice?
Try this mini challenge: Create a list of your favorite movies, add two more, remove one, then print them all with a for
loop. You’ll be surprised how easy it gets!