[Python] How do I find the index of an element in a list in Python? [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of strings, for example ['apple', 'banana', 'cherry'], and I need to find the position (index) of a specific item, such as 'banana'.

    I tried using list.find('banana'), but this resulted in an AttributeError. I was expecting it to return the index 1, similar to how the find() method works for strings. I also considered looping through the list with a for loop, but I believe there's a more direct and efficient built-in method to accomplish this.

    Continue reading...

Compartilhe esta Página