-3

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?

jscs
  • 63,095
  • 13
  • 148
  • 192

1 Answers1

6

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.

VHarisop
  • 2,745
  • 1
  • 13
  • 25