Python Enumerate For

The enumerate function in Python is used to get the index of the items in an iterable. The Python Enumerate for, adds a counter to the for loop as show in the example below.

#Python enumerate for
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
for index, day in enumerate(days):
  print(index, day)


-----------------------------------------------------
#Output
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday

Comments

Popular posts from this blog

How to write to a file in Kotlin

Python Tkinter example