In Python Programming, to convert Python Tuple to List, we use list method. As we mentined in other lessons, we can create lists with list method. So, to create a list from a python tuple, we can also use python list method.
Here, to convert Python Tuple to List, we will use the tuple as the parameter of the list method like below:
Normally, cars is a python tuple. But with this code and with python function method, we convert python tuple to the python list. The output of this python code will be:
You can practice below!
You can also check Tuple Methods of Python
You can also watch the video of this lesson!
Let’s do this with a number tuple.
You can also check Python Tuple Unpacking
We use Tuple List convertion for different purposes. One of these purposes is to change the content of python tuple. To do this, firsty we change Tuple to List with the help of list method. And then, we change the members of the created list. We can add or remove members. And then, we can convert python list to tuple with tuple method.
Let’s give an example to understand this usage better:
As you can see below,in the output of this code, you will see the new member in the python tuple.
As we have mentined in the python tuple vs list lesson, python tuples are immutable. We can not change python tuples. For example there is no usage like python tuple append. In other words, we can not use append method with tuples to add a new tuple member. But with this trick we can do this.
In this lesson, we have learned how to convert Python Tuple to List. We have created a pyhon list with the help of a tuple. Then we have learned how to modify a tuple with a trich way with the help of list function and tuple fucntion. You can use this method to do this job in your following codes.