.index()

Published May 5, 2021Updated Sep 3, 2021
Contribute to Docs

Finds the first occurence of a particular value within the list.

Syntax

list.index(value, start, end)

The .index() list method has three parameters:

  • value: The string to search for. (Required)
  • start: The index to start the search. Default is index 0.
  • end: The position to end the search. Default is end of the string.

Example 1

To find the index the first 'pen' within the backpack list:

Code
Output
Loading...

Example 2

To find the index the first 'pen' within the backpack list within index 3 to index 6:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy