Page 95 - tp_Modula_v2.0
P. 95
Program 4: To do indexing in a tuple.
Program4.py
File Edit Format Run Options Window Help
tuple=(162, [7, "Orange", 15.5], (2, "Orange Education", 70.5))
print(tuple[0])
print(tuple[1])
print(tuple[2])
print(tuple[1][2])
print(tuple[2][1])
On running the above program, you will get the following output:
Output
162
[7, 'Orange', 15.5]
(2, 'Orange Education', 70.5)
15.5
Orange Education
Negative Indexing
The negative indexing means searching for elements by using the index (position) from the
ends. This means that the last element of the array is the first element in the negative indexing
which is -1. The index -1 refers to the last element, -2 indexes refers to the second last element,
and so on.
Program 5: To do negative indexing.
Program5.py
File Edit Format Run Options Window Help
tuple=(162, [7, "Orange", 15.5], (2, "Orange Education", 70.5))
print(tuple[-1])
print(tuple[-2])
print(tuple[-3])
On running the above program, you will get the following output:
Output
(2, 'Orange Education', 70.5)
[7, 'Orange', 15.5]
162
Tuple in Python 93

