names_tuple = ("Rick", "John", "Gavin", "Troy")
# Access second item
result = names_tuple[2]
print(result)
Output
Gavin
We can also use negative indexing to access the tuple items. This will start the search from the end.
Code Example - Get the last item from the list
names_tuple = ("Rick", "John", "Gavin", "Troy")
result = names_tuple[-1]
print(result)
Output
Troy
Code Example - Access the second last item from the list
names_tuple = ("Rick", "John", "Gavin", "Troy")
result = names_tuple[-2]
print(result)
Output
Gavin
0 Comments