W3Schools Python Enumerate Tutorial Guide

Logan Jul 13, 2026

Python, with its simplicity and readability, has become one of the most popular programming languages. When it comes to iterating through lists, the `enumerate()` function is an incredible tool that's both powerful and efficient. W3Schools, a renowned website for web developers and programmers, provides an excellent tutorial on this topic. Let's dive into the world of Python's `enumerate()` function, guided by the insights from W3Schools.

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)

The `enumerate()` function in Python adds a counter to an iterable and returns it, making it an excellent tool for looping over something that needs to be indexed, like a list or a string. It essentially works as a helper function that takes in an iterable ( lists, tuples, dictionaries, sets) and returns it while adding a counter.

Write Cleaner Python Loops with enumerate()
Write Cleaner Python Loops with enumerate()

`enumerate()` Basics

At its core, `enumerate()` takes an iterable `obj` and returns an iterator containing tuples. Each tuple in the iterator contains a counter and the value of the element from the original iterable at the respective index.

Python Developer (@Python_Dv) on X
Python Developer (@Python_Dv) on X

The first argument to `enumerate()` is the iterable object, and the second argument is the `start` index. By default, the start index is 0, but you can change it to start the index from a different number.

Indexing from Start

Ultimate Python Cheat Sheet for Beginner
Ultimate Python Cheat Sheet for Beginner

The `start` parameter lets you start the index from any number. Setting it to 1, for instance, makes the first item of the iterable appear at index 1, not 0.

Here's an example to illustrate this:

list1 = ['apple', 'banana', 'mango']
for i, fruit in enumerate(list1, start=1):
  print(i, fruit)

This will output:

5 Python Tricks That Will Save You Hours of Coding
5 Python Tricks That Will Save You Hours of Coding

1 apple
2 banana
3 mango

Using `enumerate()` with `if` statement

The counter provided by `enumerate()` can be used in conditional statements to control the flow of the loop. Here's an example that demonstrates this:

Let's say we want to add a price to every fruit in our list, but we only want to add a price if the fruit is not an apple. We can use an `if` statement to achieve this:

30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast

list1 = ['apple', 'banana', 'mango']
for i, fruit in enumerate(list1):
  if fruit != 'apple':
    print(i, fruit, 0.50)
  else:
    print(i, fruit)

This will output:

0 apple
1 banana 0.5
2 mango 0.5

`enumerate()` with `else` clause

Python Learning Path for Beginners 2026 🚀
Python Learning Path for Beginners 2026 🚀
Python Input & Output Explained 🐍 | Beginner's Guide
Python Input & Output Explained 🐍 | Beginner's Guide
Shortcut to learn Python.[Cheatsheet]
Shortcut to learn Python.[Cheatsheet]
three different types of python programming
three different types of python programming
Sum of Two Numbers in Python or Adding Two Numbers
Sum of Two Numbers in Python or Adding Two Numbers
Python Notes for Beginners (Easy + Quick Guide)
Python Notes for Beginners (Easy + Quick Guide)
a poster with the words python master notes written in different languages and numbers on it
a poster with the words python master notes written in different languages and numbers on it
an info sheet with the words 10 python one - liners that will blow your mind
an info sheet with the words 10 python one - liners that will blow your mind
Best Free Websites to Learn Python for Beginners
Best Free Websites to Learn Python for Beginners
an info sheet with the words important method in python, set list and keywords
an info sheet with the words important method in python, set list and keywords
the sum all numbers in a list python
the sum all numbers in a list python
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Learn Python Basics Fast ⚡
Learn Python Basics Fast ⚡
Python Unit 5 Cheat Sheet 🐍 | File Handling & OOP Basics (AKTU)
Python Unit 5 Cheat Sheet 🐍 | File Handling & OOP Basics (AKTU)
Python List Methods
Python List Methods
a poster with the words python master notes
a poster with the words python master notes
Python Programming, Python
Python Programming, Python
Python Decoded: Beginner Edition
Python Decoded: Beginner Edition
Python Lists Explained: Complete Beginner Cheat Sheet
Python Lists Explained: Complete Beginner Cheat Sheet

Python's `enumerate()` also works with the `else` clause. The `else` block is executed after the loop finishes running, i.e., after all items in the iterable have been processed. Here's an example:

Let's say we want to output a custom message when we've reached the last item in our list. We can use an `else` clause to do this:

list1 = ['apple', 'banana', 'mango']
for i, fruit in enumerate(list1):
  print(i, fruit)
else:
  print("This is the last item in the list")

This will output:

0 apple
1 banana
2 mango
This is the last item in the list

Understanding `enumerate()` expands your Python toolbox significantly, allowing you to work more efficiently with lists and other iterables. Whether you're a seasoned programmer or just starting with Python, the insights from W3Schools serve as an invaluable resource for mastering this essential function.

Now that you've explored `enumerate()` in depth, you're ready to tackle more complex Python tasks. Why not try writing a script that uses `enumerate()` to count the number of occurrences of each letter in a string? The possibilities are endless!