Easy Tutorial
❮ Python Simplestopwatch Python Square Root ❯

Python3 List index() Method

Python3 List


Description

The index() function is used to find the index of the first occurrence of a value in a list.

Syntax

The syntax for the index() method is:

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

Parameters

Return Value

This method returns the index of the searched object. If the object is not found, it raises an exception.

Example

The following example demonstrates the use of the index() function:

Example 1

#!/usr/bin/python3

list1 = ['Google', 'tutorialpro', 'Taobao']
print('tutorialpro index is', list1.index('tutorialpro'))
print('Taobao index is', list1.index('Taobao'))

The output of the above example is:

tutorialpro index is 1
Taobao index is 2

Example 2

#!/usr/bin/python3

list1 = ['Google', 'tutorialpro', 'Taobao', 'Facebook', 'QQ']
# Search from the specified position
print('tutorialpro index is', list1.index('tutorialpro', 1))

The output of the above example is:

tutorialpro index is 1

Python3 List

❮ Python Simplestopwatch Python Square Root ❯