How to Loop Through a List in Python

If you want to work with every item in a Python list, you usually use a loop.

This page shows the main ways to loop through a list in Python:

  • Read each item one by one
  • Print or use each value
  • Get both the index and the value
  • Choose the simplest loop for your task

Quick answer #

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

for item in items:
    print(item)

Output:

apple
banana
cherry

Use a for loop when you want to process each item in a list one by one.

What this page helps you do #

  • Loop through every item in a list
  • Print or use each value
  • Get the item position with enumerate()
  • Choose the simplest loop for the task

Loop through a list with a for loop #

This is the most common and beginner-friendly way.

When you write for item in items, Python gives you one list item at a time.
The variable item holds the current value in each loop.

Use this when you only need each value.

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

for item in items:
    print(item)

Output:

apple
banana
cherry

How it works #

  • items is the list
  • item is a temporary variable
  • The loop runs once for each value in the list

You can also do other work inside the loop:

prices = [10, 20, 30]

for price in prices:
    print(price * 2)

Output:

20
40
60

If you are new to loops, see Python for loops explained.

Get both index and value with enumerate() #

Use enumerate() when you need both:

  • the position of the item
  • the item itself

This is better than creating your own counter in most cases.

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

for index, item in enumerate(items):
    print(index, item)

Output:

0 apple
1 banana
2 cherry

This is useful for numbered output:

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

for index, item in enumerate(items):
    print(f"{index}: {item}")

Output:

0: apple
1: banana
2: cherry

Why enumerate() is useful #

  • It keeps your code shorter
  • It avoids manual counters
  • It makes it clear that you need both index and value

If you want to learn more, read Python enumerate() function explained.

Loop through a list with range() and indexes #

Use range(len(my_list)) when you need to work with positions directly.

This style is useful when you want to update list items by index.

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

for index in range(len(items)):
    print(index, items[index])

Output:

0 apple
1 banana
2 cherry

When this approach helps #

This pattern is common when changing values in the original list:

numbers = [1, 2, 3]

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

print(numbers)

Output:

[10, 20, 30]

Why not use it for everything? #

For simple reading, this is less readable than:

for item in items:
    print(item)

So use range(len(...)) only when you really need index access.

If needed, you can also read Python range() function explained and how to get the length of a list in Python.

Loop through a list with a while loop #

A while loop gives you more control, but you must manage the index yourself.

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

index = 0

while index < len(items):
    print(items[index])
    index += 1

Output:

apple
banana
cherry

Important #

In a while loop, you must increase the index yourself:

index += 1

If you forget this, the loop may never end.

Use a while loop only when you need extra control over:

  • the index
  • the stopping condition
  • more complex loop logic

For most list loops, a for loop is simpler and safer.

When to use each approach #

Choose the loop style based on what you need:

Use for item in my_list #

Use this for most tasks.

for item in items:
    print(item)

Best when:

  • You only need each value
  • You want the clearest code

Use enumerate() #

Use this when you need both index and value.

for index, item in enumerate(items):
    print(index, item)

Best when:

  • You want the position and the value
  • You need numbered output

Use range(len(my_list)) #

Use this when you need to work with positions directly.

for index in range(len(items)):
    items[index] = items[index].upper()

Best when:

  • You need to change items by index
  • You need direct index access

Use while #

Use this only when the logic needs manual control.

index = 0
while index < len(items):
    print(items[index])
    index += 1

Best when:

  • You need custom stopping logic
  • You need full control over the index

Common mistakes #

Here are some common beginner mistakes when looping through lists.

Changing the loop variable does not change the original list item #

This code does not update the list:

numbers = [1, 2, 3]

for num in numbers:
    num = num * 10

print(numbers)

Output:

[1, 2, 3]

The variable num only holds a value for the current loop.
It does not replace the item inside the list.

To change the real list items, use indexes:

numbers = [1, 2, 3]

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

print(numbers)

Output:

[10, 20, 30]

Using range(my_list) instead of range(len(my_list)) #

This is wrong:

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

for index in range(items):
    print(index)

range() needs a number, not a list.

Use this instead:

for index in range(len(items)):
    print(index)

Forgetting to increase the index in a while loop #

This causes a problem:

items = ["apple", "banana", "cherry"]
index = 0

while index < len(items):
    print(items[index])

The value of index never changes, so the loop keeps running.

Fix it like this:

items = ["apple", "banana", "cherry"]
index = 0

while index < len(items):
    print(items[index])
    index += 1

Mixing up items and indexes #

This code is a common mistake:

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

for item in items:
    print(items[item])

Here, item is "apple", "banana", and "cherry".
Those are values, not index numbers.

If you need indexes too, use enumerate():

for index, item in enumerate(items):
    print(index, item)

FAQ #

What is the easiest way to loop through a list in Python? #

Use a for loop:

for item in my_list:
    print(item)

It is the simplest and most common option.

How do I get the index while looping through a list? #

Use enumerate(). It gives you both the index and the value in each loop.

for index, item in enumerate(my_list):
    print(index, item)

Should I use while or for to loop through a list? #

Use for in most cases.

Use while only when you need manual control over the index or stopping condition.

Can I change list items while looping? #

Yes, but you usually need indexes.

A loop with range(len(my_list)) is often used for that:

numbers = [1, 2, 3]

for index in range(len(numbers)):
    numbers[index] += 1

print(numbers)

Output:

[2, 3, 4]

See also #

Press Esc to close