Learn Python in 30 Days — Day 10: Lists
Learn Python in 30 Days — Day 10: Lists
Welcome to Day 10 of the Learn Python in 30 Days series!
All example files for this series are available on my GitHub: Learn-Python-in-30-Days
Last time we explored while loops and saw how to repeat tasks until a condition changes.
Today, you’ll learn about one of Python’s most useful tools, lists and use them to build your very first Shopping List Manager.
Step 1 – What Is a List?
A list is like a digital container that holds multiple pieces of data — numbers, words, or even other lists.
Output:
You can store anything inside a list it’s one of Python’s most flexible data structures.
Try it yourself, hopefully you'll see something like that shown below: -
You can also download this example from my GitHub here and run it yourself.Step 2 – Indexing (Accessing Items)
Each item in a list has a position (index).
Python starts counting at 0.
Try changing a value:
Step 3 – Slicing (Getting Parts of a List)
Slicing allows you to extract sections of a list — like cutting a loaf of bread into smaller pieces.
The basic syntax is:
-
start → the index to begin at (included)
-
end → the index to stop before (excluded)
Python doesn’t count the final position in the slice — this is called end-exclusive indexing.
Let’s see it in action:
Here’s what happens visually:
| Index | Value |
|---|---|
| 0 | 10 |
| 1 | 20 |
| 2 | 30 |
| 3 | 40 |
| 4 | 50 |
-
numbers[1:4]→ starts at index 1 (20) and stops before 4 →[20, 30, 40] -
numbers[:3]→ starts from the beginning and goes up to (but not including) index 3 →[10, 20, 30] -
numbers[-2:]→ starts from the second last item and goes to the end →[40, 50]
You can even use a step value to skip through items:
This is super useful when processing large data lists, generating sequences, or splitting text.
Tip: Negative slicing is powerful too.
Try it yourself, hopefully you'll see something like that shown below: -You can also download this example from my GitHub here and run it yourself.
Try it yourself, hopefully you'll see something like that shown below: -You can also download this example from my GitHub here and run it yourself.Step 4 – Adding & Removing Items
Lists are dynamic, meaning you can grow or shrink them freely — no need to declare sizes like in other programming languages.
Let’s begin:
Output:
Adding Items
There are several ways to add data:
Result:
Removing Items
You can remove items by name, index, or method:
Clearing the List
If you ever want to start fresh:
Quick Recap
| Action | Method | Example |
|---|---|---|
| Add one item | .append(x) | groceries.append("milk") |
| Add many | .extend([...]) | groceries.extend(["eggs", "bread"]) |
| Insert anywhere | .insert(index, x) | groceries.insert(0, "coffee") |
| Remove by value | .remove(x) | groceries.remove("bread") |
| Remove by index | del | del groceries[2] |
| Remove last & return | .pop() | groceries.pop() |
| Clear all | .clear() | groceries.clear() |
Try it yourself, hopefully you'll see something like that shown below: -
Try it yourself, hopefully you'll see something like that shown below: -Step 5 – Looping Through a List
Combine what you learned from for loops:
Output:
Try it yourself, hopefully you'll see something like that shown below: -You can also download this example from my GitHub here and run it yourself.
Try it yourself, hopefully you'll see something like that shown below: -You can also download this example from my GitHub here and run it yourself.Mini-Project – Shopping List Manager
Now let’s use lists to build a real mini-program!
How it works
-
Starts with an empty list
-
Lets you add or remove items in a loop
-
Ends when the user types “quit”
You’ve just created an interactive, data-driven program! Hopefully you'll see something like that shown below: -
You can also download this example from my GitHub here and run it yourself.
You can also download this example from my GitHub here and run it yourself.Next up — Day 11 – Tuples & Sets
All example files for this series are available on my GitHub: Learn-Python-in-30-Days
You can see the full series here Learn Python in 30 Days series!
Hope you have enjoyed this post, thanks Matty






Comments
Post a Comment