There are two common methods used with python tuples. In this lesson, we will focus on these Python Tuple Methods. So what are the Tuple Methods used in python? These are:
Index method is used to access the specified item in the python tuple. With this method, we can access any item in the tuple with an index number given in a square brackets. We can also access to a range of items by using one more parameters with index method.
You can also check Python List Methods
If we use one number, we can access this item only. Let’s show this with an example:
You can watch also the video of this lesson!
You can also check Python Tuples versus Python List
If we give two parameters divided with colon ( : ), we can access a range of items.
You can practice below!
If we use also the third operator, we can access the range of items and we can also jump on these items.
We can also use negative indexes to access any item in the tuple:
The output of this python tuple index method will be like below:
The other method used with python tuples is python count method. With this method, we can count the number of any items in the python tuple.
For example, for the below tuple, let’s count 10.
As you can see below, the output of this python tuple count method will be 3. Because there are three 10s in this tuple.
In this lesson, we have learned the Python Tuple Methods. You can use these methods for different purposes and for different examples.