🧪 Python Test Worksheet: List, Tuple, Set &
Dictionary
Instructions: - Attempt all questions. - Write Python code for each question.
- Use built-in methods where applicable. - Do not use AI or external help.
🔹 SECTION A: LIST TEST
Q1. List Creation & Access
1. Create a list of 6 integers.
2. Print:
o First element
o Last element
o Elements from index 1 to 4
a = [1,2,3,4,5,6]
print (a[0], a[5])
print(a[1:4])
Q2. List Methods
Given:
numbers = [10, 20, 30, 40]
Perform the following: 1. Add 50 at the end 2. Insert 15 at index 1 3. Remove
30 4. Sort the list in descending order 5. Print the final list
Q3. List Update
Replace the 3rd element of a list with 999.
Q4. Looping Through List
Write a program to print only even numbers from a list.
Q5. List Comprehension
Create a list of squares of numbers from 1 to 10.
# a = [1,2,3,4,5,6]
# # print (a[0], a[5])
# # print(a[1:4])
# numbers = [10,20,30,40]
# [Link](4,50)
# [Link](1,15)
# [Link](numbers[3])
# [Link](reverse = True)
# numbers[3] = 999
# for num in numbers:
# if num % 2 == 0:
# print(num)
# print(numbers)
# numbers = [1,2,3,4,5,6,7,8,9,10]
# for num in numbers:
# print (num ** 2)
🔹 SECTION B: TUPLE TEST
Q6. Tuple Creation
1. Create a tuple of 5 strings.
2. Print:
o Length of the tuple
o Last two elements
Q7. Tuple Methods
Given:
data = (10, 20, 30, 20, 40)
1. Count occurrences of 20
2. Find index of 30
Q8. Tuple Unpacking
Unpack the tuple (1, 2, 3) into three variables and print them.
Q9. Tuple to List Conversion
Convert a tuple into a list and add a new element.
Q10. Tuple Membership
Check if an element exists in a tuple.
🔹 SECTION C: SET TEST
Q11. Set Creation
Create a set with duplicate values and print it.
Q12. Set Methods
Given:
my_set = {10, 20, 30}
1. Add 40
2. Remove 20
3. Check if 30 exists
4. Print the final set
Q13. Set Operations
Given:
A = {1, 2, 3, 4}
B = {3, 4, 5, 6}
Find: 1. Union 2. Intersection 3. Difference (A - B)
Q14. Loop Through Set
Print each element of a set using a loop.
🔹 SECTION D: DICTIONARY TEST
Q15. Dictionary Creation
Create a dictionary storing: - Student name - Age - Grade
Q16. Dictionary Access & Update
Given:
student = {"name": "Ali", "age": 20, "marks": 85}
1. Print student name
2. Update marks to 90
3. Add key "city"
Q17. Dictionary Methods
Using the dictionary above: 1. Print all keys 2. Print all values 3. Print all key-
value pairs
Q18. Looping Through Dictionary
Print keys and values using a loop.
Q19. Dictionary Membership
Check if key "age" exists in the dictionary.
Q20. Nested Dictionary
Create a dictionary of two students, each having: - Name - Marks
🔹 BONUS SECTION
Q21. Logic Based
From a list of numbers: 1. Create a set of unique values 2. Create a
dictionary where: - Key = number - Value = square of number
Q22. Type Conversion
Perform the following conversions: 1. List → Tuple 2. Tuple → Set 3. Set → List
End of Test
Good luck! 💻🐍