
Dictionary
Authored by Sonam Tenzin
Computers
8th Grade
Used 3+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is a dictionary in Python?
A data structure that stores items in a sorted manner.
A collection of elements arranged in a linear sequence.
A collection of key-value pairs.
A way to store only numeric values.
Answer explanation
A dictionary is a collection of keys and values. Dictionaries can not have duplicated items, meaning the keys are unique. A dictionary is defined using curly brackets {}. The key & value pair is defined using a colon (:) - key:value.
The syntax to define a dictionary:
dictionary_name = {key1:value1, key2:value2,...}
For example:
shopping_list = {"eggs":12 , "milk":2, "apples":5, "tomatoes": 6}
2.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you create an empty dictionary in Python?
my_dict = {}
my_dict = []
my_dict = ()
my_dict = None
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you access the value associated with a specific key in a dictionary?
By using the index of the value.
By using the value as an index.
By using the key as an index.
By using the value's position in the dictionary.
Answer explanation
You access the value associated with a specific key in a dictionary by using square brackets and placing the key inside the brackets. This allows you to retrieve the value (or data) that corresponds to that particular key.
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Can a dictionary in Python contain duplicate keys?
Yes, but only if the values are different.
No, dictionaries cannot have duplicate keys.
Yes, but it will cause an error when accessing values.
Yes, but only if the keys are numbers.
Answer explanation
No, a dictionary in Python cannot contain duplicate keys. Each key in a dictionary must be unique. If you attempt to add a key that already exists in the dictionary, it will overwrite the existing key-value pair with the new value.
Remember that keys in a dictionary must be unique, and adding a key that already exists will simply update the associated value.
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you add a new key-value pair to an existing dictionary?
dictionary.add(key, value)
dictionary.insert(key, value)
dictionary[key] = value
dictionary.append(key, value)
Answer explanation
You can add a new key-value pair to an existing dictionary by assigning a value to a new key using square brackets. If the key already exists, the assignment will update the value for that key; if it doesn't exist, a new key-value pair will be added to the dictionary.
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What happens if you try to access a key that doesn't exist in a dictionary?
Python raises an error.
Python returns the value None.
Python returns an empty string.
Python returns a special "key not found" value.
Answer explanation
You will encounter a KeyError exception. This is because dictionaries in Python use keys to look up and retrieve values, and if the specified key is not found in the dictionary, Python raises a KeyError to indicate that the key does not exist.
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you remove a key-value pair from a dictionary?
dictionary.remove(key)
del dictionary[key]
dictionary.pop(key)
dictionary.delete(key)
Answer explanation
The pop() method removes the item with the specified key name:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
print(thisdict)
The del keyword can also delete the dictionary completely.
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict["model"]
print(thisdict)
The clear() method empties the dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.clear()
print(thisdict)
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
Programming Constructs
Quiz
•
5th - 11th Grade
11 questions
HEALTH AND SAFETY 9
Quiz
•
7th - 9th Grade
15 questions
LEDs on micro:bit
Quiz
•
8th Grade
15 questions
Quiz 1
Quiz
•
1st - 12th Grade
14 questions
Games Industry Jobs
Quiz
•
8th Grade
10 questions
ICT Grade 8
Quiz
•
8th Grade
13 questions
Guess the Retro Computer 1
Quiz
•
KG - Professional Dev...
10 questions
KEIRO PROGRAMMING
Quiz
•
4th - 12th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade