Question 1
Question
Keys in dictionary are of mutable type but values can be immutable.
Question 2
Question
List is enclosed in square brackets
Question 3
Question
Slicing is used to extract a part of the list
Question 4
Question
Each key is separated from its value by a colon.
Question 5
Question
Keys are unique and act as the index.
Question 6
Question
If a is a dictionary with some key-value pairs, what does a.popitem() do?
Answer
-
Removes an arbitrary element
-
Removes all the key-value pairs
-
Removes the key-value pair for the key given as an argument
-
Invalid method for dictionary
Question 7
Question
What will be the output of the following Python code snippet?
>>> a={1:"A",2:"B",3:"C"}
>>> del a
Answer
-
method del doesn’t exist for the dictionary
-
del deletes the values in the dictionary
-
del deletes the entire dictionary
-
del deletes the keys in the dictionary
Question 8
Question
Which of the statements about dictionary values if false?
Answer
-
More than one key can have the same value
-
The values of the dictionary can be accessed as dict[key]
-
Values of a dictionary must be unique
-
Values of a dictionary can be a mixture of letters and numbers
Question 9
Question
What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(5,4))
Answer
-
Error, invalid syntax
-
A
-
5
-
4
Question 10
Question
What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
Question 11
Question
What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
Answer
-
1 A 2 B 3 C
-
1 2 3
-
A B C
-
1:”A” 2:”B” 3:”C”
Question 12
Question
Which of these about a dictionary is false?
Answer
-
The values of a dictionary can be accessed using keys
-
The keys of a dictionary can be accessed using values
-
Dictionaries aren’t ordered
-
Dictionaries are mutable
Question 13
Question
Suppose list Example is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
Answer
-
[3, 4, 5, 20, 5, 25, 1]
-
[1, 3, 3, 4, 5, 5, 20, 25]
-
[3, 5, 20, 5, 25, 1, 3]
-
[1, 3, 4, 5, 20, 5, 25]
Question 14
Question
To add a new element to a list we use which command?
Answer
-
list1.add(5)
-
list1.append(5)
-
list1.addLast(5)
-
list1.addEnd(5)
Question 15
Question
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
Question 16
Question
Suppose list1 is [1, 6, 9], what is sum(list1)?
Question 17
Question
Suppose list1 is [2445,133,12454,123], what is min(list1)?
Question 18
Question
Which of the following commands will create a list?
Answer
-
list1 = list()
-
list1 = []
-
list1 = list([1, 2, 3])
-
all of the mentioned
Question 19
Question
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
Answer
-
[2, 33, 222, 14]
-
Error
-
25
-
[25, 14, 222, 33, 2]
Question 20
Question
What will be the output of the following Python code?
>>>"Welcome to Python".split()
Answer
-
[“Welcome”, “to”, “Python”]
-
(“Welcome”, “to”, “Python”)
-
{“Welcome”, “to”, “Python”}
-
“Welcome”, “to”, “Python”