Python - Negative index of Element in List Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report We are given a list we need to find the negative index of that element. For example, we are having a list li = [10, 20, 30, 40, 50] and the given element is 30 we need to fin the negative index of it so that given output should be -3.Using index()index() method in Python searches for the first occurrence of a specified element in a list and returns its index. In this example s.index(ele) directly finds and returns the index of the element ele in the list s. Python li = [10, 20, 30, 40, 50] ele = 30 # Find the positive index and convert it to negative p = li.index(ele) n = -(len(li) - p) - 1 print(f"Negative index of {ele}: {n}") OutputNegative index of 30: -3 Explanation:Code reverses list using li[::-1] and then uses index() method to find index of the element from reversed list.Negative index is calculated by subtracting index of element from length of the list adjusted for a negative index.Using reversed() and index()Using reversed() to reverse list and index() to find the index of element within reversed list provides an efficient way to determine the negative index. Python li = [10, 20, 30, 40, 50] ele = 30 # Reverse the list and find index n = -list(reversed(li)).index(ele) - 1 print(f"Negative index of {ele}: {n}") OutputNegative index of 30: -3 Explanation:List is reversed using reversed() and the index() function is used to find index of the element in the reversed list.Negative index is obtained by negating the result of the index in the reversed list and subtracting one to adjust for the reversed order.Using a loop Manually iterating through list in reverse order we can find the index of the given element loop checks each element starting from the last one and when the element is found it calculates the negative index based on position from the end. Python li = [10, 20, 30, 40, 50] ele = 30 # Loop through the list and calculate the negative index n = -1 for i in range(len(li)-1, -1, -1): if li[i] == ele: n = -(len(li) - i) break print(f"Negative index of {ele}: {n}") OutputNegative index of 30: -3 Explanation:Loop iterates over list in reverse order starting from last element and moving towards the first. It checks each element to see if it matches the target element (ele).When the element is found the negative index is calculated by subtracting the current index from the total length of the list ensuring the result is in negative form. Comment More info M manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 6 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like