In this pythin tuple program, we will convert a list into a tuple and multiply each element.
Steps to solve the program
- Create a list and an empty list.
- Use for loop to iterate over elements in the list.
- Multiply each element by 2 and add it to the empty list.
- Now convert the new list to a tuple using tuple().
- Print the output.
list1 = [12,65,34,77]
list2 = []
for ele in list1:
a = 2*ele
list2.append(a)
tup = tuple(list2)
print("Origianl list: ",list1)
print("After multiplyting by 2: ",tup)
Output :
Origianl list: [12, 65, 34, 77]
After multiplyting by 2: (24, 130, 68, 154)
remove an item from a tuple.
1 thought on “Convert a list into a tuple and multiply each element”