Python How To Loop Through A List

4 min read

In Python, looping through a list means going through each item in a list one at a time so you can read, change, check, or process it. Learning python how to loop through a list is one of the most important skills for beginners because lists are everywhere in Python programming, from storing student names and product prices to managing numbers, dictionaries, objects, and more complex data. Whether you are building a simple calculator, working with user input, analyzing data, or creating a game, you will often need to repeat an action for every item in a list Easy to understand, harder to ignore. Surprisingly effective..

Introduction to Python Lists

A list in Python is a collection of items stored in a specific order. Lists are flexible, easy to use, and can contain many different types of data.

For example:

fruits = ["apple", "banana", "cherry"]
numbers = [10, 20, 30, 40]
mixed = ["Python", 123, True, 3.14]

Each item in the list has an index, which starts at 0. This means the first item is at index 0, the second item is at index 1, and so on.

fruits = ["apple", "banana", "cherry"]

print(fruits[0])  # apple
print(fruits[1])  # banana
print(fruits[2])  # cherry

Looping through a list allows you to work with each item without manually writing code for every index.

Method 1: Using a Basic for Loop

The most common and recommended way to loop through a list in Python is with a for loop Small thing, real impact. Nothing fancy..

fruits = ["apple", "banana", "cherry"]

for fruit in fruits:
    print(fruit)

Output:

apple
banana
cherry

In this example, the variable fruit represents one item from the list at a time. On the first loop, fruit is "apple". On the second loop, it is "banana". On the third loop, it is "cherry".

The basic structure is:

for item in list_name:
    # code to repeat

This is the simplest way to loop through a list in Python. It is clean, readable, and efficient.

Method 2: Looping Through a List with enumerate()

Sometimes you need both the item and its index. For that, Python provides the built-in function enumerate().

fruits = ["apple", "banana", "cherry"]

for index, fruit in enumerate(fruits):
    print(index, fruit)

Output:

0 apple
1 banana
2 cherry

By default, enumerate() starts counting at 0, which matches Python’s list indexing system. You can also start counting from another number:

fruits = ["apple", "banana", "cherry"]

for number, fruit in enumerate(fruits, start=1):
    print(number, fruit)

Output:

1 apple
2 banana
3 cherry

This is useful when you want to display a numbered list:

tasks = ["wake up", "study Python", "practice coding"]

for task_number, task in enumerate(tasks, start=1):
    print(f"{task_number}. {task}")

Output:

1. wake up
2. study Python
3. practice coding

Use enumerate() when you need to know where an item is in the list as well as what the item is.

Method 3: Looping Through a List by Index

You can also loop through a list using its index with the range() function.

numbers = [10, 20, 30, 40]

for index in range(len(numbers)):
    print(numbers[index])

Output:

10
20
30
40

Here, len(numbers) gives the number of items in the list. In this example, the list has 4 items, so range(len(numbers)) creates indexes from 0 to 3 It's one of those things that adds up..

This approach is useful when you need to modify list items by index:

numbers = [10, 20, 30]

for index in range(len(numbers)):
    numbers[index] = numbers[index] * 2

print(numbers)

Output:

[20, 40, 60]

Even so, for most cases, looping directly over items is easier and more Pythonic:

for number in numbers:
    print(number)

Use range(len(list)) when you specifically need the index Less friction, more output..

Method 4: Looping Through Multiple Lists with zip()

Python also lets you loop through multiple lists at the same time using zip().

names = ["Alice", "Bob", "Charlie"]
scores = [90, 85, 95]

for name, score in zip(names, scores):
    print(f"{name} scored {score}")

Output:

Alice scored 90
Bob scored 85
Charlie scored 95

This is helpful when related pieces of data are stored in separate lists Worth keeping that in mind..

For example:

products = ["keyboard", "mouse", "monitor"]
prices = [25, 15, 120]

for product, price in zip(products, prices):
    print(f"{product}: ${price}")

Output:

keyboard: $25
mouse: $15
monitor: $120

One important thing to know: zip() stops when the shortest list ends. If one list has more items than the others, the extra items will not be processed Most people skip this — try not to..

Method 5: Using a while Loop

Although for loops are usually preferred for lists, you can also use a while loop But it adds up..

numbers = [5, 10, 15, 20]

index = 0

while index 
New This Week

Just Went Live

Readers Also Loved

Explore a Little More

Thank you for reading about Python How To Loop Through A List. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home