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)

Sample Output:

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

Python Code Editor:

Improve this sample solution and post your code through Disqus