Python List index() Method

Example

The position of the value "cherry" is:

fruits = ['apple', 'banana', 'cherry']
x = fruits.index("cherry")

Run Instance

Definition and Usage

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

Syntax

list.index(element)

Parameter Value

Parameter Description
element Required. Any type (string, number, list, etc.). The value to be searched.

More Examples

Example

The position of the value 32 is:

fruits = [4, 55, 64, 32, 16, 32]
x = fruits.index(32)

Run Instance

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