Robotics & Artificial Intelligence
Write a Python program that creates a tuple with elements from a list. Your program should do the following:
- Create a list with multiple elements.
- Convert the list to a tuple.
- Print the tuple and demonstrate accessing an element of the tuple.
Python List Manipulation
5 Likes
Answer
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)Output
Tuple: (10, 20, 30, 40, 50)
Element at index 2: 30
Answered By
2 Likes