-1

In Python if you have a list:

list = [ cow , dog , cat ] 

Is it possible to find what index an element is at?

Is there a command which does something like:

{some code}(cow) 

and have it say something like cow = 0?

1
  • going through pydocs would have given you answer instantaneously. Commented Jan 30, 2015 at 2:07

1 Answer 1

7

Of course there is. Try

>>> ['cow', 'dog', 'cat'].index('cow') 0 

May i suggest, don't use list as a variable name, as it is already used for constructing a list object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.