Python convert tuple to list

By: On:

In this Python tutorial, we will discuss how to convert tuple to list in python. Also, we will discuss:

  • Python convert tuple to list
  • Python convert tuple to dictionary
  • Python convert a tuple to string
  • Python convert list to a tuple
  • Python convert a tuple to an array

How to convert tuple to list in Python? To convert tuple to a list Python, we can use the list() function value = (10, 20, 30, 40, 50); my_tuple = list(value)

Python convert tuple to list

We can use the list() function to convert tuple to list in Python.

Example:

value = (10, 20, 30, 40, 50)
my_tuple = list(value)
print(my_tuple)

After writing the above code, Ones you will print ” my_tuple ” then the output will appear as a “ [10, 20, 30, 40, 50] ”.

Here, the list() function will convert the tuple to the list. Refer the screenshot for python convert tuple to list.


Python convert tuple to list

In this way, we can convert a tuple to list in python.

You may like following Python list tutorials:

Python convert tuple to dictionary

In python, to convert a tuple to the dictionary we will use dict() function and tuple as an argument. which will contain key-value pairs.

Example:

value = ((20, 'Ahana'), (21, 'Tom'))
my_dictionary = dict(value)
print(my_dictionary)

After writing the above code (Python convert tuple to dictionary), Ones you will print ” my_dictionary ” then the output will appear as a “ {20: ‘Ahana’, 21: ‘Tom’} ”. Here, the dict() function will convert the tuple to the dictionary. You can refer to the below screenshot for python convert tuple to dictionary.

Python convert tuple to dictionary
convert tuple to dictionary in python

In this way, we can convert a tuple to dictionary in python.

You may like following Python dictionary tutorials:

Python convert a tuple to string

In python, to convert tuple to string we will use join() method to append all the elements of tuple to form a string.

Example:

value = ('s', 't', 'r', 'i', 'n', 'g')
my_string = ''.join(value)
print(my_string)

After writing the above code (Python convert tuple to string), Ones you will print ” my_string ” then the output will appear as a “ string ”. Here, the join() function will append all items and it will convert the tuple to the string. You can refer to the below screenshot for python convert tuple to string.

Python convert a tuple to string
convert tuple to string python

In this way, we can convert a tuple to string in python.

You may like following Python string tutorials:

Python convert list to a tuple

In python, to convert list to a tuple we will use tuple() method for converting list to tuple.

Example:

value = ['Tim', 'John', 'Mark']
my_tuple = tuple(value)
print(my_tuple)

After writing the above code (Python convert list to a tuple), Ones you will print ” my_tuple ” then the output will appear as a “ (‘Tim’, ‘ John’, ‘Mark’) ”. Here, the tuple() method will convert the list into a tuple. You can refer to the below screenshot for the python convert list to a tuple.

Python convert list to a tuple
convert list to a tuple in python

Python convert a tuple to an array

In python, to convert a tuple to an array we will use list constructor in python.

Example:

my_tuple = (101, 102, 103)
value = list(my_tuple)
print(value)

After writing the above code (Python convert a tuple to an array), Ones you will print ” value ” then the output will appear as a “ [101, 102, 103] ”. Here, the tuple will be converted to an array list.

You can refer to the below screenshot to convert a tuple to an array

Python convert a tuple to an array
Python convert a tuple to an array

In this way, we can convert list to a tuple in python.

In this tutorial, we learned how to convert tuple to list in Python, Python convert tuple to dictionary, Python convert a tuple to string, Python convert list to a tuple, Python convert a tuple to an array.

Leave a Comment