in this tutorial we'll learn how to get index in for loop python

syntax

1
list.index(element)

example 1:

1
2
3
4
5
6
7
8
#syntax
#list.index(element)

#list
list_a = ['Dog', 'Cat', 'Zebra', 'Tiger']

for i in list_a:
    print("element {} in in index {}".format(i, list_a.index(i)))

output

element Dog in in index 0                                                                                                             
element Cat in in index 1                                                                                                             
element Zebra in in index 2                                                                                                           
element Tiger in in index 3     

example 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#list
list_a = ['Dog', 'Cat', 'Zebra', 'Tiger']
#index
index = 0

#loop
for i in list_a:
    print("element {} is in index {}".format(i, index))
    index += 1
    

output

element Dog is in index 0                                                                                                             
element Cat is in index 1                                                                                                             
element Zebra is in index 2                                                                                                           
element Tiger is in index 3      

English today is not an art to be mastered it's just a tool to use to get a result