Python List index() Method
Example
What is the position of the value "cherry":
fruits = ['apple', 'banana', 'cherry']
x = fruits.index("cherry")
Try it Yourself »
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)
Try it Yourself »
Note: The index()
method
only returns the first occurrence of the value.