
- 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
How to get the second-to-last element of a list in Python?
Python sequence, including list object allows indexing. Any element in list can be accessed using zero based index. If index is a negative number, count of index starts from end. As we want second to last element in list, use -2 as index.
>>> L1=[1,2,3,4,5] >>> print (L1[-2]) 4
- Related Articles
- How to get the last element of a list in Python?
- Python How to get the last element of list
- Python program to sort a list according to the second element in sublist
- How to get Second Element of the Tuple in C#?
- How to get the second last record from a table in MySQL?
- Python program to sort a list according to the second element in the sublist.
- How to get the last element in JavaScript array?
- Last occurrence of some element in a list in Python
- Get last second of a date in MySQL?
- How to find the last occurrence of an element in a Java List?
- How to get last element in android ConcurrentLinkedDeque?
- Get last element of each sublist in Python
- Get the second last row of a table in MySQL?
- How to get last day of a month in Python?
- Get first and last elements of a list in Python

Advertisements