If in lists two element is repeated , index of its first place is shown, why?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If in lists two element is repeated , index of its first place is shown, why??

l=['a','b','c','a','s'] print(l.index('a'))=0 why it's only 0 (3 should also be their)

22nd Oct 2018, 1:03 PM
Divam kachoria
Divam kachoria - avatar
1 Answer
+ 7
It's just how the index method works. It returns the index of the first occurrence of the element.
22nd Oct 2018, 1:10 PM
Nikhil
Nikhil - avatar