Tuples are used to store a list of items. Tuples are defined using parenthesis. Tuples are immutable. This means that tuples cannot be modified. Only information can be accessed about tuples.
Example:
numbers = (4, 8, 3, 7)
print(numbers)
Output:
(4, 8, 3, 7)
Accessing the tuples:
You can access items in the tuple by passing index between [].
Example:
numbers = (4, 8, 3, 7)
print(numbers[1])
Output:
8
You can get the occurrence of a specific item from a tuple by using the count() method.
Example:
numbers = (4, 8, 3, 7, 4)
print(numbers.count(4))
Output:
2
You get the index of the first occurrence of a specific item by using the index() method.
Example:
numbers = (4, 8, 3, 7, 4)
print(numbers.index(4))
Output:
0