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 item in tuple by passing index between [].
Example:
numbers = (4, 8, 3, 7)
print(numbers[1])
Output:
8
You can get occurrence of specific item from tuple by using count() method.
Example:
numbers = (4, 8, 3, 7, 4)
print(numbers.count(4))
Output:
2
You get index of first occurrence of specific item by using index() method.
Example:
numbers = (4, 8, 3, 7, 4)
print(numbers.index(4))
Output:
0