
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Negative index of Element in List
When it is required to get the negative index of an element in a list, the ‘len’ method and the ‘index’ method are used.
Below is a demonstration of the same −
Example
my_list = [52, 47, 18, 22, 23, 57, 13] print("The list is :") print(my_list) my_key = 22 print("The value of key is ") print(my_key) my_result = len(my_list) - my_list.index(my_key) print("The result is :") print(my_result)
Output
The list is : [52, 47, 18, 22, 23, 57, 13] The value of key is 22 The result is : 4
Explanation
A list of integers is defined and is displayed on the console.
A key is defined and is displayed on the console.
The difference between the length of the list and element present at specific key is determined.
This is assigned to a variable.
This is displayed as output on the console.
- Related Articles
- Python program to compute the power by Index element in List
- How to remove an element from a list by index in Python?
- Find index of 0 or Any Negative Integer Element Present in Array in Java
- How to find what is the index of an element in a list in Python?
- Python – Index Value repetition in List
- C# program to find the index of an element in a List
- Program to find index, where we can insert element to keep list sorted in Python
- Python Index specific cyclic iteration in list
- Equate two list index elements in Python
- Python program to print negative numbers in a list
- How to find the index of given element of a Java List?
- Find minimum of each index in list of lists in Python
- How to remove index list from another list in python?
- How to remove element from the specified index of the List in C#?
- Python – Append List every Nth index

Advertisements