Python Program to Convert List to Tuple

Write a Python Program to Convert a List to Tuple. In Python, we have a tuple function that converts the List items to Tuple. This Python example uses the tuple function to convert the list to a tuple.

# Convert List to Tuple

intList = [11, 22, 33, 44 ,55]
print("List Items     = ", intList)
print("List Data Type = ", type(intList))

intTuple = tuple(intList)
print("\nTuple Items     = ", intTuple)
print("Tuple Data Type = ", type(intTuple))
Python Program to Convert List to Tuple 1

Python Program to Convert List to Tuple Example 2

It allows users to enter list items and used different options to convert that list to Tuple.

# Convert List to Tuple

list1 = []

number = int(input("Enter the Total List Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d List value = " %i))
    list1.append(value)
    
print("List Items     = ", list1)
print("List Data Type = ", type(list1))

intTuple = tuple(list1)
print("\nTuple Items     = ", intTuple)
print("Tuple Data Type = ", type(intTuple))

intTuple1 = (*list1,)
print("\nTuple Items     = ", intTuple1)
print("Tuple Data Type = ", type(intTuple1))
Enter the Total List Items = 4
Enter the 1 List value = 20
Enter the 2 List value = 50
Enter the 3 List value = 120
Enter the 4 List value = 90
List Items     =  [20, 50, 120, 90]
List Data Type =  <class 'list'>

Tuple Items     =  (20, 50, 120, 90)
Tuple Data Type =  <class 'tuple'>

Tuple Items     =  (20, 50, 120, 90)
Tuple Data Type =  <class 'tuple'>