Python Programming
About Lesson

Tuples are also having positive and negative indices to access and modify their values.

#Example code access tuple elements using indices
tup1 = (‘physics’, ‘chemistry’, 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print (“tup1[0]: “, tup1[0]);
print (“tup2[1:5]: “, tup2[1:5]);

Negative indexing means beginning from the end, -1 refers to the last item, -2 refers to the second last item etc.

Example
#Print the last item of the tuple
thistuple = (“apple”, “banana”, “cherry”)
print(thistuple[-1])

You cannot copy content of this page