Tuple(Python)
1. Create and Print a Tuple
Create a tuple with the values (10, 20, 30, 40, 50) and print it.
2. Access Tuple Elements
Given the tuple t = (1, 2, 3, 4, 5), print the second and fourth elements.
3. Concatenate Two Tuples
Given the tuples t1 = (1, 2, 3) and t2 = (4, 5, 6), concatenate them and print the
result.
4. Find Length of Tuple
Given the tuple t = ('apple', 'banana', 'cherry'), find and print the length of the
tuple.
5. Count Occurrences of an Element
Given the tuple t = (1, 2, 3, 4, 2, 5, 2), count how many times the number 2
appears in the tuple.
6. Tuple Slicing
Given the tuple t = (1, 2, 3, 4, 5), slice and print the elements from index 2 to index 4
(inclusive).
7. Check if Element Exists in Tuple
Given the tuple t = (10, 20, 30, 40, 50), check if the number 30 exists in the tuple and
print True or False.
8. Convert Tuple to List
Given the tuple t = (1, 2, 3, 4), convert it to a list and print the resulting list.
9. Nested Tuple
Create a tuple with another tuple inside it, like (1, (2, 3), 4), and print the inner tuple.
10. Unpacking a Tuple
Given the tuple t = (1, 2, 3), unpack it into three separate variables and print the values of
those variables.