THE WORLD'S LARGEST WEB DEVELOPER SITE

Python List index() Method

❮ List Methods


Example

What is the position of the value "cherry":

fruits = ['apple', 'banana', 'cherry']

x = fruits.index("cherry")
Run example »

Definition and Usage

The index() method returns the position at the first occurrence of the specified value.


Syntax

list.index(elmnt)

Parameter Values

Parameter Description
elmnt Required. Any type (string, number, list, etc.). The element to search for

More Examples

Example

What is the position of the value 32:

fruits = [4, 55, 64, 32, 16, 32]

x = fruits.index(32)
Run example »

Note: The index() method only returns the first occurrence of the value.

❮ List Methods