Python Tuples is an immutable collection of that are more like lists.
Python Provides a couple of methods to work with tuples.
In this article, we will discuss these two methods in detail with the help of some examples.
Method | Description |
---|---|
The count() method of Tuple returns the number of times the given element appears in the tuple. | |
The Index() method returns the first occurrence of the given element from the tuple. |
()
The
The
It returns the number of times a given value occurs in a string or a list, as the name implies.
Example
a=(5,3,4,5,7,2,5,7,4,2,5,4,5,)
b=a.count(4)
print (b) #Output is 3
()
The
The
The tuple
This function basically performs two functions: Giving the first occurrence of an element in the tuple.
Raising an exception if the element mentioned is not found in the tuple.
Example
a=(1,2,3,4,2,3,4,2,4,5,6,4,4,5,6)
b=a.index (4)
print (b) #Output is 3