Example:
tuple = ("python", "includehelp", 43, 54.23)
Accessing front and rear elements of tuple
In this article, we will be learning to access front and rear elements of the tuple in Python programming language using different methods.
Input:
(4, 1, 7, 8, 5, 3)
Output:
4, 3
Extracting the first and last, elements can be done easily by getting the value at index 0 and n-1. This can be done in Python using multiple ways.
Method 1:
One method to extract the elements at the first and last index is by using the bracket expression as we extract in a list.
Output:
Method 2:
Another method to solve the problem is by using Python's itemgetter operation from the operator library. The itemgetter returns the values at the required index from the calling collection.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer