WorksheetsDay 2
Total questions: 10
Worksheet time: 2mins
Which of the following data types in Python is mutable?
String
Tuple
List
Dictionary
What will be the output of the following code?
my_tuple = (1, 2, 3)
my_tuple[0] = 4
print(my_tuple)
(1, 2, 3)
(4, 2, 3)
Error: Tuple indices must be integers, not strings
Error: Tuple object does not support item assignment
Which data type in Python is used to store a collection of elements with no duplicate values?
Set
List
Tuple
Dictionary
Which of the following is NOT a valid way to create a dictionary in Python?
my_dict = {}
my_dict = dict()
my_dict = {1: 'one', 2: 'two', 3: 'three'}
my_dict = {'one': 1, 'two': 2, 'three': 3}
What is the result of the expression: len("Hello World")?
5
10
11
12
Which of the following data types in Python allows duplicate elements?
List
Tuple
Set
Dictionary
What will be the type of the following expression: type((1,2))?
List
Tuple
Set
str
What will be the output of the following code?
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
x is greater than 5
x is less than or equal to 5
x is equal to 5
What will be the output of the following code?
for i in range(3):
print(i)
012
111
000
123
What is the purpose of the else clause in a loop
It executes when a loop is terminated prematurely using break.
It executes when a loop condition becomes False
It executes if an exception is raised inside the loop
It executes after each iteration of the loop
