`index()`

function is a part of python programming language and it is used to **find the index of an element in list**. Here element is the item of the list that `index()`

method receives and try to find out its position index. Remember this position index starts from `o`

, not from `1`

.

Let suppose there is a list with items (

If the the input value occurs more than one time (

`a, b, c, d`

) and we want to find the index of `'c'`

. So, how we find the index of value `'c'`

. The value `'c'`

will passed to the `index()`

method and the method will return the index `'2'`

.If the the input value occurs more than one time (

`a, b, c, d, c`

) then index will show the position of very first element and ignore the others.

## Syntax of `index()`

Function

The syntax of `index()`

function in Python is:

1 | list.index(x[, start[, end]]) |

## Parameters of `index()`

Function in Python

`x`

– Where `x`

is any valid item passed as an argument. This is actually the value which we want to know the position index. This parameter is required.

## Compatibility

`index()`

function is available and compatible with both Python `2.x`

and `3.x`

. This function is one of python list methods.

## Return Value of `index()`

Function in Python

`index()`

function will return a zero-based index of the given input in a list.

## Python `index()`

Function Example 1

There is a list of different fruits (apple, grapes, banana) and the goal is to find the index of a fruit grapes.

1 2 3 4 5 | # a fruits list fruits = ['apple', 'grapes', 'banana'] #Printing the index of blue print(fruits.index('grapes')) |

Output:

`1`

This is the index of color grapes.

## Python `index()`

Function Example 2

Now, there is a list of different colors (red, yellow, green, blue, orange, blue) and notice here blue color repeat twice.

1 2 3 4 5 | # a colors list colors = ['red', 'yellow', 'green', 'blue', 'orange', 'blue'] #Printing the index of blue print(colors.index('blue')) |

Output:

`3`

Now, here is the index and this is the index of first blue color not second.