w3resource logo


Python Exercises

Python Exercise: Convert a list to a tuple

Python tuple: Exercise-11 with Solution

Write a Python program to convert a list to a tuple.

Sample Solution :-

Python Code :

>>> #Convert list to tuple
>>> listx = [5, 10, 7, 4, 15, 3]
>>> print(listx)
>>> #use the tuple() function built-in Python, passing as parameter the list
>>> tuplex = tuple(listx)
>>> print(tuplex)

Output:

>>>
[5, 10, 7, 4, 15, 3]
(5, 10, 7, 4, 15, 3)
>>>

Python Code Editor:

#Convert list to tuple
listx = [5, 10, 7, 4, 15, 3]
print(listx)
#use the tuple() function built-in Python, passing as parameter the list
tuplex = tuple(listx)
print(tuplex)

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Python: How to check whether a file exists using Python?

C#: Loops in c#

PHP: For each

SQL: JOIN using more than 5 tables

JavaScript: Blank Slide in Javascript Slideshow