THE DEFINITIVE GUIDE

Everything you need to know about enumerate()

Use python’s enumerate function to change the way you loop forever

Aaron S
Published in
6 min readFeb 7, 2020

--

The first exposure to loops in python usually starts with looping over a basic sequence. One of the functions you learn about to do this is the range function. The range function returns a sequence of numbers and used to loop over an item in a sequence.

Sometimes it’s necessary to need to know the index of a sequence, that is the order of the sequence. Whenever you see within your code range(len(…)) there is a better way to loop than through using an index! This comes up in programming more than you would think! This is where the built-in function enumerates can help.

In this article you will be exposed to a built-in function that I will convince you is more readable and will change the way you do looping in the future.

In this article, you will learn

  1. The basic syntax of the enumerate built-in function
  2. Understand what the enumerate object does
  3. Understand behind the scenes of the enumerate function
  4. Examples of the enumerate function in simple code
  5. How to unpacking sequences

--

--

Aaron S
Analytics Vidhya

Hello! My name is Aaron. Healthcare professional with an interest in python, technology, education and healthcare.I run coding-medic.com for python enthusiasts.