Q:

Python | Program to Print the index of first matched element of a list

belongs to collection: Python List Programs

0

Given a list and we have to find the index of first matched of a list in Python.

Example:

    Input:
    List = [10, 20, 10, 20, 30, 40, 50]
    element = 10
    Output: 
    Index of first matched 10 is: 0

    Input:
    List = [10, 20, 10, 20, 30, 40, 50]
    element = 30
    Output:
    Index of first matched 20 is: 4

list.index() Method

It’s an inbuilt method in Python, it returns the index of first matched element of a list.

Syntax:

 list.index(element)

Here, list is the name of the list and element is the element/item whose first matched index to be returned.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to find the index of first matched element in Python

# declare a list of Integers
list = [10, 20, 10, 20, 30, 40, 50]

# printing index of 10 
print (list.index (10))

#printing index of 20
print (list.index (20))

# printing index of 30
print (list.index (30))

# printing index of 40
print (list.index (40))

# printing index of 50
print (list.index (50))

Output

    0
    1
    4
    5
    6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python List Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Program to find the position of minimum a... >>
<< Python | Program to find the differences of two li...