0% found this document useful (0 votes)
6 views2 pages

Tuple (Python)

The document provides a series of Python exercises focused on tuples, including creating, accessing, concatenating, and manipulating tuples. It covers tasks such as finding the length of a tuple, counting occurrences of an element, slicing, checking for element existence, converting tuples to lists, and unpacking tuples. Each exercise is clearly defined with specific examples to illustrate the concepts.

Uploaded by

kaduprajwal406
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Tuple (Python)

The document provides a series of Python exercises focused on tuples, including creating, accessing, concatenating, and manipulating tuples. It covers tasks such as finding the length of a tuple, counting occurrences of an element, slicing, checking for element existence, converting tuples to lists, and unpacking tuples. Each exercise is clearly defined with specific examples to illustrate the concepts.

Uploaded by

kaduprajwal406
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like