WorksheetsDictionary Methods 2026
Total questions: 40
Worksheet time: 40mins
What will be the output for the program above?
<class 'tuple'>
<class 'list'>
<class 'set'>
<class 'dict'>
Which code segment, when inserted in the blank, will set the "Year" from 2006 to 2008?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
__________________________________
OUTPUT: 2008
birthday["Year"]=2008
birthday[Year]=2008
birthday [2008]
birthday[2006]=2008
What will be the output of this program when executed?
student = {"name": "Jordan", "grade": 11,"gender": "Male"}
result = student.setdefault("name", "Unknown")
print(student)
{'grade': 11, 'gender': 'Male', 'name': 'Unknown'}
{'name': 'Jordan', 'grade': 11, 'gender': 'Male'}
{'name': 'Unknown'', grade': 11, 'gender': 'Male'}
{'Unknown'}
What will be the output once this code executes?
Bruce Wayne
Male
Gotham
DC Comics
gender
What will be the output of this program when executed?
student = {"name": "Alex", "grade": 10, "gender": "Female"}
result = student.setdefault("age", 15)
print(student)
{'name': 'Alex', 'grade': 10, 'gender': 'Female', 'age': 15}
{'name': 'Alex', 'grade': 10, 'gender': 'Female'}
{'age': 15, 'name': 'Alex', 'grade': 10, 'gender': 'Female'}
{'name': 'Alex', 'grade': 10, 'gender': 'Female', 'age': 'Unknown'}
What will be the output of this program when executed?
student = {"name": "Alice","grade": 10,"gpa": 3.8}
student_copy = student.copy()
student_copy["name"] = "Bob"
print(student_copy)
{'name': 'Alice', 'grade': 10, 'gpa': 3.8}
{'name': 'Alice', 'grade': 10, 'gpa': 3.8, 'name': 'Bob',}
{'name': 'Bob', 'grade': 10, 'gpa': 3.8}
{'name': 'Alice', 'grade': 10, 'gpa': 3.8, 'name': 'Alice', 'grade': 10, 'gpa': 3.8}
What will be the output of this program when executed?
employee = {"id": 101, "department": "HR", "salary": 50000}
employee_copy = employee.copy()
employee_copy["department"] = "Finance"
print(employee_copy)
{'id': 101, 'department': 'HR', 'salary': 50000}
{'id': 101, 'department': 'HR', 'salary': 50000, 'department': 'Finance'}
{'id': 101, 'department': 'Finance', 'salary': 50000}
{'id': 101, 'department': 'HR', 'salary': 50000, 'id': 101, 'department': 'HR', 'salary': 50000}
What will be the output once this code executes?
{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020}
{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020, 4: 2000}
4
{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2000, 5: 2018, 6: 2020}
2000
What will be the output of this program when executed?
fruits = ["Apple", "Banana", "Cherry"]
prices = dict.fromkeys(fruits, 5)
print(prices)
{'Apple': 5, 'Banana': 5, 'Cherry': 5}
{'Apple', 'Banana', 'Cherry'}
{5, 5, 5}
[('Apple', 5), ('Banana', 5), ('Cherry', 5)]
What will be the output of this program when executed?
students = ["Amy", "Brian", "Carlos"]
scores = dict.fromkeys(students, 0)
print(scores)
{'Amy': 0, 'Brian': 0, 'Carlos': 0}
{'Amy', 'Brian', 'Carlos'}
{0, 0, 0}
[('Amy', 0), ('Brian', 0), ('Carlos', 0)]
What will be the output once this code executes?
{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020}
{0: 1981, 1: 1986, 3: 1996, 4: 2004, 5: 2018, 6: 2020}
{0: 1981, 1: 1986, 2: 0, 3: 1996, 4: 2004, 5: 2018, 6: 2020}
{0: 1981, 1: 1986, 2: 1992, 4: 2004, 5: 2018, 6: 2020}
What will be the output once this code executes?
{0: 0, 0: 0, 0: 0, 0: 0, 0: 0, 0: 0, 0: 0}
{0: 1981, 0: 1986, 0: 1996, 0: 2004, 0: 2018, 0: 2020}
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
{}
What will be the output once this code executes?
97
87
100
81
81
100
87
97
Algebra
Biology
English
History
History
English
Biology
Algebra
What will be the output once this code executes?
97
87
100
81
81
100
87
97
Algebra
Biology
English
History
History
English
Biology
Algebra
What will be the output once this code executes?
Bruce Wayne
Male
Gotham
DC Comics
Information not found
What will be the output for the program above?
<class 'tuple'>
<class 'list'>
<class 'set'>
<class 'dict'>
What will be the output once this code executes?
Bruce Wayne
Male
Gotham
DC Comics
Information not found
What will be the output for the code above?
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]
[0, 1, 2]
['Python', 'Java', 'JavaScript']
['Guido Rossum', 'James Gosling', 'Brendan Eich']
What will be the output for the code above?
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]
[0, 1, 2]
['Python', 'Java', 'JavaScript']
['Guido Rossum', 'James Gosling', 'Brendan Eich']
What will be the output for the code above?
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]
[0, 1, 2]
['Python', 'Java', 'JavaScript']
['Guido Rossum', 'James Gosling', 'Brendan Eich']
What will be the output for the code above?
[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('JavaScript', 'Brendan Eich')]
James Gosling
['Python', 'JavaScript', 'C']
['Guido Rossum', 'Brendan Eich', 'Dennis Ritchie']
What will be the output for the code above?
[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('JavaScript', 'Brendan Eich')]
['Python', 'Java', 'JavaScript']
['Guido Rossum', 'James Gosling', 'Brendan Eich']
['Guido Rossum', 'Brendan Eich', 'Dennis Ritchie']
Which command below would you need to type to print the weight of Wolverine?
Wolverine ={"real name":"James Howlett", "alias":"Logan", "height":"5ft 3 in", "weight":300}
Wolverine.get(weight)
print(Wolverine.values("weight"))
print(Wolverine.get("weight"))
print(Wolverine.keys("weight"))
A Python dictionary stores ...
value - key pairs
key - value pairs
Items are accessed by their index position in a dictionary
True
False
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
A dictionary is ordered alphabetically by its keys
true
false
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
print(d["john"] )
40
45
“john”
“peter”
6. Can you modify the value of a specific key in a dictionary in Python? If yes, how?
Yes, you can modify the value of a specific key in a dictionary in Python by simply assigning a new value to that key.
No, you can only add new keys to a dictionary in Python
In Python, Dictionaries are immutable
True
False
Given the dictionary d = {'spring': 'autumn', 'autumn': 'fall', 'fall': 'spring'}, what would the following code print?
print (d.get('autumn'))
spring
fall
autumn
none
What will be the output for the program above?
{'winter': 25, 'spring': 72, 'summer': 90}
{'winter': 25, 'spring': 72, 'summer': 90, 'autumn': 60}
{ }
winter
What will be the output for the code above?
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]
[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]
['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']
Given the dictionary d = {'spring': 'autumn', 'autumn': 'fall', 'fall': 'spring'}, what would the following code print?
print (d.get('winter', "spring"))
spring
autumn
winter
fall
What will be the output for the code above?
['Python', 'Java', 'JavaScript', 'C']
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]
[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]
['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']
Which of the following will give error?
Suppose dict1={"a":1,"b":2,"c":3}
print(len(dict1))
print(dict1.get("b"))
dict1["a"]=5
None of these.
What will be the output for the code above?
['Python', 'Java', 'JavaScript', 'C']
[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]
[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]
['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']
Which block of code creates a key ‘age’ in dictionary D and assigns a value of 25 for this key?
D={25}
D = {}
D[‘age’] = 25
D = {}
D = 25
none of the mentioned
Given the dictionary d = {'cat': 'dog', 'dog': 'wolf', 'wolf': 'cat'}, what would the following code print?
print (d.get('lion', "cat"))
cat
dog
lion
wolf
What will be the output to the console when this program executes?
{'winter': 25, 'spring': 72, 'summer': 90, 'autumn': 60}
0
{ 0 }
{ }
