Write a Python program to convert a list to a tuple


The program defines a list l containing 6 integer elements. The print() function is used to output the entire list, as well as its data type (list) using the type() function.

Next, the tuple() function is used to convert the list l into a tuple. The result is assigned to the variable t, which is then printed to the console along with its data type (tuple) using the print() and type() functions.

As a result, the output will show the original list l, its data type, the newly created tuple t, and its data type. The conversion from list to tuple is demonstrated, and it can be seen that the elements in the list are unchanged, but the data type has changed from list to tuple.

Source Code

l = [12,45,87,54,89,4]
print(l)
print(type(l))
t = tuple(l)
print(t)
print(type(t))
 

Output

[12, 45, 87, 54, 89, 4]
<class 'list'>
(12, 45, 87, 54, 89, 4)
<class 'tuple'>


Example Programs