menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

enumerate in Python
source image

Dev

1M

read

309

img
dot

Image Credit: Dev

enumerate in Python

  • enumerate() is a function in Python used to create an iterable with numbers incremented by 1.
  • It takes the iterable as the first argument and an optional start value (default is 0).
  • The iterable cannot be directly accessed with an index; you need to use list() to access it with an index.
  • Enumerate can be used to iterate over a list along with the index value.
  • It returns tuples containing the index and the corresponding item from the iterable.
  • Using enumerate in a for loop allows you to loop over both the index and item simultaneously.
  • Enumerate can be nested within itself, and also used in combination with other functions like zip().
  • Zip function can combine two iterables into a single iterable of tuples.
  • It pairs elements from each iterable based on their indices.
  • Zip can be useful when you want to iterate over two iterables together.

Read Full Article

like

18 Likes

For uninterrupted reading, download the app