Questão 1
Questão
What is the output of the following
sampleDict = dict([
('first', 1),
('second', 2),
('third', 3)
])
print(sampleDict)
Responda
-
[ (‘first’, 100), (‘second’, 200), (‘third’, 300) ]
-
Options: SyntaxError: invalid syntax
-
{‘first’: 1, ‘second’: 2, ‘third’: 3}
Questão 2
Questão
Select the correct ways to get the value of marks key.
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
Responda
-
m = student.get(2)
-
m = student.get(‘marks’)
-
m = student[2])
-
m = student[‘marks’])
Questão 3
Questão
Dictionary keys must be immutable
Questão 4
Questão
Select the correct way to access the value of a history subject
sampleDict = {
"class":{
"student":{
"name":"Mike",
"marks":{
"physics":70,
"history":80
}
}
}
}
Responda
-
sampleDict[‘class’][‘student’][‘marks’][1]
-
sampleDict[‘class’][‘student’][‘marks’][‘history’]
-
sampleDict[‘class’][0][‘marks’][‘history’]
Questão 5
Questão
What is the output of the following code
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
Questão 6
Questão
What is the output of the following dictionary operation
dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.get("age")
print(temp)
Questão 7
Questão
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
Responda
-
del student
-
del student[0:2]
-
student.clear()
Questão 8
Questão
In Python, Dictionaries are immutable
Questão 9
Questão
Select the correct way to print Emma’s age.
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'}, 2: {'name': 'Mike', 'age': '22', 'sex': 'Male'}}
Responda
-
student[0][1]
-
student[1][“age”]
-
student[0][“age”]
Questão 10
Questão
What is the output of the following dictionary operation
dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.pop("age")
print(temp)
Responda
-
KeyError: ‘age’
-
None
-
25
-
age
Questão 11
Questão
Select all correct ways to copy a dictionary in Python
Questão 12
Questão
Select the all correct way to remove the key ‘marks‘ from a dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
Responda
-
student.pop(“marks”)
-
del student[“marks”]
-
student.popitem()
-
dict1.remove(“key2”)
Questão 13
Questão
Select correct ways to create an empty dictionary
Responda
-
sampleDict = {}
-
sampleDict = dict()
-
sampleDict = dict{}
Questão 14
Questão
Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.