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

Tuples Lists Sets Worksheet

This practice worksheet covers data structures in Python, specifically focusing on tuples, lists, and sets. It includes exercises for creating, modifying, and accessing elements in these data structures, as well as operations like slicing, counting, and checking for existence. The worksheet is divided into three sections, each dedicated to one of the data structures with practical tasks to enhance understanding.

Uploaded by

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

Tuples Lists Sets Worksheet

This practice worksheet covers data structures in Python, specifically focusing on tuples, lists, and sets. It includes exercises for creating, modifying, and accessing elements in these data structures, as well as operations like slicing, counting, and checking for existence. The worksheet is divided into three sections, each dedicated to one of the data structures with practical tasks to enhance understanding.

Uploaded by

23f2004066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practice Worksheet: Data Structures - Tuples, Lists & Sets (Python)

Section 1: Tuples

1. Create a tuple with elements (1, 2, 3, 4, 5). Print the tuple.

2. Access the 2nd and 4th elements from the tuple (10, 20, 30, 40, 50).

3. Try to modify the first element of a tuple. What happens?

4. Count how many times the number 3 appears in the tuple (1, 3, 3, 7, 8).

5. Use slicing to print the first 3 elements of a tuple.

6. Create a tuple with different data types: an integer, a string, and a float.

7. Use the `in` keyword to check if a value exists in a tuple.

Section 2: Lists

1. Create a list with the values [10, 20, 30, 40, 50]. Print it.

2. Append the value 60 to the list and print the updated list.

3. Insert the value 15 at index 1 in the list.

4. Remove the value 30 from the list.

5. Sort the list in ascending and then in descending order.

6. Replace the 2nd element of the list with 99.

7. Slice the list to get the middle three elements.

8. Use a for loop to print each element of the list.

9. Create a list with repeated elements and use `.count()` to count a value.

10. Convert a list to a tuple using `tuple()`.

Section 3: Sets

1. Create a set with values {1, 2, 3, 4, 5}. Print the set.

2. Add the value 6 to the set and print it.

3. Try to add a duplicate value to the set. What happens?

4. Remove a value from the set using `.remove()` or `.discard()`.

5. Find the union of two sets: {1, 2, 3} and {3, 4, 5}.

6. Find the intersection of sets: {1, 2, 3} and {2, 3, 4}.

7. Find the difference between sets: {1, 2, 3, 4} - {2, 4}.


Practice Worksheet: Data Structures - Tuples, Lists & Sets (Python)

8. Use `in` to check if a value exists in a set.

9. Convert a list with duplicate values to a set to remove duplicates.

10. Create a set from a string and observe what happens (e.g., set("hello")).

You might also like