7(iii)
Write a Python program that creates a tuple with elements from a list. Your program should do the following:
- (a)Create a list with multiple elements.
- (b)Convert the list to a tuple.
- (c)Print the tuple and demonstrate accessing an element of the tuple.
Show SolutionHide Solution↓
my_list = [10, 20, 30, 40, 50]
my_tuple = tuple(my_list)
element = my_tuple[2]
print("Tuple:", my_tuple)
print("Element at index 2:", element)
Tuple: (10, 20, 30, 40, 50)
Element at index 2: 30