DEMO: Read the instructions below and use the code in the editor to test using a value to find its index.

We can use a value in the .index() command to get that value's index (position) in a list.

  • Every time you run this activity, the pets list is created containing a monkey, parrot, snake and penguin sprite in a random order! Run the activity more than once to see the snake's index every time the list is randomized!

Replace snake on line 16 with with any of the other sprite names to find that sprite's position in the pets list.

To navigate the page using the TAB key, first press ESC to exit the code editor.

  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)