Articles

Program to find index of element in list in python in Python

Program to find index of element in list in python in Python


In the python programming article, we are going to learn

  • program to find index of element in list in python

Program to find index of element in list in python in Python

The program to find index of element in list in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

my_list = [22,11,34,78,61,35,91,77,59]

try:
    index_of_91 = my_list.index(91)
    print("Element is at {} index position!".format(index_of_91))
except:
    print("The element is not present in the list!")

The output of the find index of element in list in python program is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Element is at 6 index position!

Few important tips about the program

1. The index() method of the python list helps us to find the index of an element in python. It takes the element a an argument.

2. But if the element is not present, it raises an exception.

3. To handle that exception we use try-except exception handler here.

 

find index of element in list in python snapshot:

find index of an element from list in python

This wraps up our session on find index of element in list in python.


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Oct 13,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!