Question
How to find the first and last elements of a tuple in python?
Solution
β Verified
Since tuples are ordered collections, you can access elements by their index. The first element is at index 0. And the last element is at index -1.
Example:--
my_tuple = (10, 20, 30, 40, 50)
first_element = my_tuple[0]
last_element = my_tuple[-1]
print("First element:", first_element)
print("Last element:", last_element)
Click here to download practice questions on
Python Tuple