Ultimate Guides on Python Tuple Lists and Methods

Python Tuples

/ins>

Python List Of Tuples

We have mentioned this before in this Python Tutorial that Tuples is basically a collection that is both ordered and unchangeable. It is important for you to remember that there is a certain emphasis that is placed on the word unchangeable here. As a developer who is using this language, it is also important for you to remember that the Python tuples is written with round brackets around them. For example, if you wish to create a tuple then

 

To Access Tuple Items

You should also remember that you can access a number of different tuple items by referring to the index number of the particular item. For example, if you want to return back to the item that is in the position 1 then

 

To Change Tuple Values

It should be a fact known to you that once you create any particular tuple value then you cannot change it. This is because of the fact that every tuple value is unchangeable. This is one of the Python tuple methods that can be illustrated with the help of the below-mentioned example

 

To Loop Through a Tuple

If you ever wish to loop through the various items that are mentioned in a tuple then it is important for you to remember that you can use the for method to perform that particular feature.

For example

If you wish to learn more about this for method in this programming language then we suggest that you should keep reading as we will be discussing that particular feature in our Python for Loops portion of this entire Python Tutorial.

 

The Tuple Length

This is one of the Python tuple methods. If you wish to determine the total number of items that are present in a list then it is suggested that you should use the len ( ) method. For example, if you wish to print the number of items that are present in a tuple then

 

To Add Items

It is important for you to remember that once you have created a tuple then you cannot add any other item to it. This is because of the fact that tuples once created are unchangeable.

For example

 

To Remove Items

We have mentioned this fact above in the Python list of tuples module that tuples once created are unchangeable. And because of that fact, you cannot remove any particular item from a tuple once it is created. However, you can delete the entire tuple with the help of the del keyword.

For example

 

The Tuple() Constructor

It is important for you to remember that in this programming language you can also construct a tuple by using the tuple () constructor.

For example


With this, we finish off our module of tuple Python in this Python Tutorial.