WorksheetsSemester Final 2025
Total questions: 40
Worksheet time: 20mins
What is the output of the following code? python mylist = [1, 2, 3] print(mylist[1])
1
2
3
Error
Which method is used to add an item at the end of a list?
insert()
add()
append()
extend()
What does mylist[-1] return?
First item
Last item
Second item
Error
Which method removes all items from a list?
clear()
delete()
remove()
pop()
What is the output of: python x = [2, 4, 6] x.append([8, 10]) print(x)
[2, 4, 6, 8, 10]
[2, 4, 6, [8, 10]]
[2, 4, 6, 8]
Error
What is the main difference between a list and a tuple?
Tuples are faster
Tuples are immutable
Lists are immutable
How do you define a tuple with one element?
(4)
[4]
(4,)
tuple(4)
Which of these methods can be used on a tuple?
append()
remove()
count()
pop()
What is the output of len((10, 20, 30))?
2
3
1
Error
Can you change the value of an element in a tuple?
Yes
Only if it’s a number
No
Only using update()
Which of these defines a dictionary correctly?
{1, 2, 3}
["a": 1, "b": 2]
{"a": 1, "b": 2}
(1, 2)
What is the output of: python copy d = {"a": 1, "b": 2} print(d.get("c"))
None
0
Error
'c'
Which method removes all elements from a dictionary?
delete()
clear()
remove()
pop()
What is a key property of a set?
Ordered
Mutable and duplicates allowed
No duplicates
Immutable
What is the output of: python copy s = {1, 2, 2, 3} print(s)
{1, 2, 2, 3}
{1, 2, 3}
Error
None
Which method is used to add a single item to a set?
append()
add()
insert()
update()
What will set1 & set2 return?
Union
Intersection
Difference
Symmetric difference
Which data structure does not allow duplicates?
List
Tuple
Dictionary
Set
Which of the following is not a valid dictionary method?
pop()
update()
add()
get()
Which statement creates an empty dictionary?
dict = ()
dict = []
dict = {}
dict = set()
Which operation is used to combine two lists?
list1.add(list2)
list1 + list2
list1.join(list2)
list1.append(list2)
What is the output of sorted([3, 1, 2])?
[1, 2, 3]
[3, 2, 1]
[1, 3, 2]
None
Which data structure allows both key-value pairs and is mutable?
List
Tuple
Set
Dictionary
What is the output of: python t = (1, 2, 3) print(t[1])
1
2
3
Error
What is the data type of 3.14?
int
float
str
double
What is the output of: python x = 5 if x < 10: print("Small") else: print("Big")
Small
Big
Error
Nothing
Which of the following is the correct syntax for an if statement?
if x < 10 then:
if(x < 10)
if x < 10:
if x < 10 {
What does the following code print? python x = 3 if x > 5: print("High") elif x > 2: print("Medium") else: print("Low")
High
Medium
Low
Error
What is the output of: python i = 1 while i < 4: print(i) i += 1
a) 1 2 3
b) 1 2 3 4
c) 0 1 2
d) 2 3 4
What is the purpose of the break statement in a loop?
Ends the program
Skips the next iteration
Exits the loop
Restarts the loop
What is the output of: python for i in range(5): if i == 3: continue print(i)
0 1 2 3 4
0 1 2 4
0 1 2
0 1 2 3
What is the keyword to define a function?
function
func
def
define
What does the following code print? python def greet(): return "Hello" print(greet())
greet
Hello
None
Error
Which of the following is not a valid function call?
sum([1, 2, 3])
print("Hi")
max(5, 9)
def(3)
What will the following function return? def add(x, y): return x + y print(add(2, 3))
23
5
x + y
Error
What does the input() function return?
Integer
Float
String
Boolean
What is the result of: python Copy name = input("Enter name: ") print("Hello", name)
Hello
name
Hello name
Hello followed by user input
What is the output of: python Copy s = "hello" print(s.upper())
HELLO
hello
Which of the following gets the last character of the string s = "python"?
s[0]
s[5]
s[-1]
s[len(s)]
What will this return? python s = "data" print(len(s))
3
4
5
Error
