How to Get Index of List Element in Python
Posted on: February 28, 2021 by Ariessa Norramli
In this article, you will learn how to get index of list element in Python.
Let’s say you have a list of cardinal directions.
directions = ['North', 'South', 'East', 'West']
Get Index of List Element in Python
In order to get the index of a list element, you can use the index()
method.
directions = ['North', 'South', 'East', 'West']
# Find index of element 'East'
index = directions.index('East')
# Display index of element 'East'
print('Index of East:', index)
# The index of East: 2
Note: The index()
method functions by returning the index of the supplied list element.
Share on social media
//