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.
In this way, we can convert a tuple to list in python.
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 a 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.
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.
In this way, we can convert a tuple to string in python.
You may like the following Python string tutorials:
- How to create a string in Python
- How to split a string using regex in python
- How to concatenate strings in python
- How to convert an integer to string in python
- Python convert list to string
- Python String Functions
- How to Convert a list to DataFrame in Python
- Python binary search and linear search
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 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
In this way, we can convert list to a tuple in python.
You may like following Python list tutorials:
- How to create a list in Python
- 11 Python list methods
- Python convert list to string
- Check if a list is empty in Python
- Python sort list of tuples
- Create a tuple in Python
- Python Array with Examples
- Function in Python
- Python Read CSV File and Write CSV File
- Python exit command
- Python concatenate tuples
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.
Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile.