Home » Python programs

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

Here, we will learn how to find and print the index of first matched element of a list? To find the index of an element, we use list.index(element) method.
Submitted by IncludeHelp, on July 25, 2018

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.