In this example we will show how to access tuple items by specifying a range of negative indexes in Python.
Source Code
my_tuple = ('a', 'b', 'c', 'd', 1, 2, 3, 4)
print(my_tuple[-6:-2])
Output:
('c', 'd', 1, 2)
In this example we will show how to access tuple items by specifying a range of negative indexes in Python.
my_tuple = ('a', 'b', 'c', 'd', 1, 2, 3, 4)
print(my_tuple[-6:-2])
Output:
('c', 'd', 1, 2)
In this example we will show how to access tuple items by referring to the index number in Python.
# the tuples are written with round brackets
my_tuple = ('a', 'b', 1, 2)
print(my_tuple[2])
Output:
1