If you have already written your first Python program β maybe a line that prints your name β you have met a variable: one box that holds one value. Real programs, though, rarely deal with just one thing. A to-do app holds many tasks, a game holds many scores, and a shop holds many prices. That is where lists come in. And when you need to do the same job for every item in a list, loops save you from writing the same line over and over again. Together, lists and loops are the two tools that turn tiny scripts into useful programs.
📅 Want a study plan for this topic?
Get a free 7-day learning plan in your calendar — one small lesson every day.
What Is a List?
A list is simply an ordered collection of values, written inside square brackets and separated by commas. Here is a shopping list in Python:
shopping = ["milk", "bread", "eggs", "rice"]
One variable now holds four items, in order. The first item sits at position 0, not 1 β Python counts from zero, which feels strange at first and becomes second nature quickly. So shopping[0] is “milk” and shopping[2] is “eggs”. Negative positions count from the end: shopping[-1] is “rice”, the last item.
Lists can hold different kinds of values, though keeping one kind in a list usually makes your code easier to read. You can also find out how many items a list holds with len(shopping), which here gives 4.
Changing a List
Unlike a single variable that you replace wholesale, a list can grow and change piece by piece:
- Add to the end with append: shopping.append(“butter”) puts butter last.
- Remove an item with remove: shopping.remove(“bread”) takes bread out.
- Change one item directly: shopping[1] = “cheese” swaps the second item.
Try these in a Python playground and print the list after each step. Watching it change is the fastest way to make the idea stick.
What Is a Loop?
A loop repeats a block of code. The most common one for beginners is the for loop, which walks through a list one item at a time:
for item in shopping:
print(item)
This prints every item, one per line, no matter whether the list has four items or four hundred. The variable item takes a new value on each pass β first “milk”, then “bread”, and so on. The indented lines under the for line are the repeated block, so indentation is not decoration in Python; it is how Python knows what belongs inside the loop.
Loops are not only for printing. Imagine adding up test scores:
scores = [78, 85, 92, 64, 88]
total = 0
for score in scores:
total = total + score
print(total)
The loop does the adding five times, and total keeps a running sum. Writing this without a loop would mean five separate additions β and a rewrite every time a new score arrived.
The Range Shortcut
Sometimes you do not have a list at all; you just want to repeat something a set number of times. That is what range() is for:
for day in range(1, 8):
print("Day", day)
This counts from 1 up to, but not including, 8 β so it prints Day 1 through Day 7. It is perfect for practice drills, countdowns, and tables. Combine it with lists and you can do things like print each item together with its position.
Lists and Loops Together: A Mini Project
Here is a small, complete example β a to-do list that you can actually run:
tasks = ["Revise Python", "Walk the dog", "Read 20 pages"]
print("Today's tasks:")
for number, task in enumerate(tasks, start=1):
print(number, "-", task)
tasks.append("Call a friend")
print("Tasks now:", len(tasks))
enumerate pairs each task with its number, starting at 1, so the output looks like a tidy numbered list. One loop, one clean result β and adding a task is a single line, not a rewrite.
Common Beginner Mistakes (and How to Avoid Them)
- Forgetting that counting starts at 0, so shopping[4] on a four-item list gives an error. When in doubt, check len() first.
- Forgetting the colon at the end of the for line, or forgetting to indent the block under it. Both are the most common first-week errors, and both are fixed in seconds once you spot them.
- Changing a list while looping over it, for example removing items inside the loop. It can skip items in confusing ways. Build a new list instead, or loop over a copy.
- Using a loop where a list already does the job. Need the total of a list of numbers? sum(scores) does it in one call. Loops are powerful, but Python’s built-in shortcuts are worth learning too.
Practical Takeaways
- A list stores many values in order inside one variable; positions start at 0.
- append, remove, and direct assignment let a list grow and change.
- A for loop repeats a block once per item, so one block handles any list size.
- range() repeats a job a fixed number of times without needing a list.
- Combine lists and loops for real jobs: totals, numbered lists, and filtering.
Letβs Trace It: A Running Total, Step by Step
The to-do list above shows lists and loops working together, but I want to show you something even more useful: what the computer is actually doing inside the loop, one round at a time. When I first learned loops, the code made sense but the flow did not β until someone showed me the running values after every single step. So here is a real example: five test scores, and we want their total and average.
scores = [78, 92, 85, 91, 88]
total = 0
for score in scores:
total = total + score
print("after adding", score, ": total =", total)
print("average:", total / len(scores))
Run it, and this is the exact output you get β nothing hidden, nothing skipped:
after adding 78: total = 78
after adding 92: total = 170
after adding 85: total = 255
after adding 91: total = 346
after adding 88: total = 434
average: 86.8
Look at the pattern: the loop runs five times, once per score, and total grows a little each round β 78, then 170, then 255, then 346, then 434. The loop does not remember anything except what you store in a variable, and that is the trick most beginners miss: if you want to keep a result, you need a variable outside the loop to hold it. I made this exact mistake in my first week β I put total = 0 inside the loop, and every round reset it to zero. My average came out as 88 divided by 5, and I stared at it for twenty minutes before spotting the bug. One line, wrong place, completely wrong answer.
Now compare with the shortcut: sum(scores) gives 434 in one call, and sum(scores) / len(scores) gives 86.8. In my opinion, learn the loop version first (so you understand what is happening), then use the shortcut in real code (so you write less). Understanding first, shortcuts second β that order has never let me down.
Try it yourself: change the list to your own five marks, run the code, and check the total by hand on paper. If your hand calculation and the program disagree, the program is not wrong β your trace is. Find the round where they split, and you have found your bug.
Conclusion
Lists answer the question “how do I hold many things?”, and loops answer “how do I do something to all of them without repeating myself?” Once you are comfortable with both, programs stop feeling like a pile of separate lines and start feeling like a machine you control: feed it a list, and one small loop does the work for every item. Practise with your own lists β your favourite songs, your weekly expenses, your class schedule β and these two ideas will quickly become the most natural part of your Python toolkit.
Learn β’ Practice β’ Build β The Geeks Guru
Keep learning
📅 Want a study plan for this topic?
Get a free 7-day learning plan in your calendar — one small lesson every day.


[…] i numbers are already sorted, so there is no point comparing them again. If you have followed my Python lists and loops guide, this code should look comfortingly familiar: it is just two loops and one if-statement doing all […]