Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Dictionary Methods 2026

Total questions: 40

Worksheet time: 40mins

Name
Class
Date
1.

What will be the output for the program above?

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

2.

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

a)

birthday["Year"]=2008

b)

birthday[Year]=2008

c)

birthday [2008]

d)

birthday[2006]=2008

3.

What will be the output of this program when executed?

student = {"name": "Jordan", "grade": 11,"gender": "Male"}
result = student.setdefault("name", "Unknown")
print(student)

a)

{'grade': 11, 'gender': 'Male', 'name': 'Unknown'}

b)

{'name': 'Jordan', 'grade': 11, 'gender': 'Male'}

c)

{'name': 'Unknown'', grade': 11, 'gender': 'Male'}

d)

{'Unknown'}

4.

What will be the output once this code executes?

a)

Bruce Wayne

b)

Male

c)

Gotham

d)

DC Comics

e)

gender

5.

What will be the output of this program when executed?

student = {"name": "Alex", "grade": 10, "gender": "Female"}
result = student.setdefault("age", 15)
print(student)

a)

{'name': 'Alex', 'grade': 10, 'gender': 'Female', 'age': 15}

b)

{'name': 'Alex', 'grade': 10, 'gender': 'Female'}

c)

{'age': 15, 'name': 'Alex', 'grade': 10, 'gender': 'Female'}

d)

{'name': 'Alex', 'grade': 10, 'gender': 'Female', 'age': 'Unknown'}

6.

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)

a)

{'name': 'Alice', 'grade': 10, 'gpa': 3.8}

b)

{'name': 'Alice', 'grade': 10, 'gpa': 3.8, 'name': 'Bob',}

c)

{'name': 'Bob', 'grade': 10, 'gpa': 3.8}

d)

{'name': 'Alice', 'grade': 10, 'gpa': 3.8, 'name': 'Alice', 'grade': 10, 'gpa': 3.8}

7.

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)

a)

{'id': 101, 'department': 'HR', 'salary': 50000}

b)

{'id': 101, 'department': 'HR', 'salary': 50000, 'department': 'Finance'}

c)

{'id': 101, 'department': 'Finance', 'salary': 50000}

d)

{'id': 101, 'department': 'HR', 'salary': 50000, 'id': 101, 'department': 'HR', 'salary': 50000}

8.

What will be the output once this code executes?

a)

{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020}

b)

{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020, 4: 2000}

c)

4

d)

{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2000, 5: 2018, 6: 2020}

e)

2000

9.

What will be the output of this program when executed?

fruits = ["Apple", "Banana", "Cherry"]
prices = dict.fromkeys(fruits, 5)
print(prices)

a)

{'Apple': 5, 'Banana': 5, 'Cherry': 5}

b)

{'Apple', 'Banana', 'Cherry'}

c)

{5, 5, 5}

d)

[('Apple', 5), ('Banana', 5), ('Cherry', 5)]

10.

What will be the output of this program when executed?

students = ["Amy", "Brian", "Carlos"]
scores = dict.fromkeys(students, 0)
print(scores)

a)

{'Amy': 0, 'Brian': 0, 'Carlos': 0}

b)

{'Amy', 'Brian', 'Carlos'}

c)

{0, 0, 0}

d)

[('Amy', 0), ('Brian', 0), ('Carlos', 0)]

11.

What will be the output once this code executes?

a)

{0: 1981, 1: 1986, 2: 1992, 3: 1996, 4: 2004, 5: 2018, 6: 2020}

b)

{0: 1981, 1: 1986, 3: 1996, 4: 2004, 5: 2018, 6: 2020}

c)

{0: 1981, 1: 1986, 2: 0, 3: 1996, 4: 2004, 5: 2018, 6: 2020}

d)

{0: 1981, 1: 1986, 2: 1992, 4: 2004, 5: 2018, 6: 2020}

12.

What will be the output once this code executes?

a)

{0: 0, 0: 0, 0: 0, 0: 0, 0: 0, 0: 0, 0: 0}

b)

{0: 1981, 0: 1986, 0: 1996, 0: 2004, 0: 2018, 0: 2020}

c)

{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}

d)

{}

13.

What will be the output once this code executes?

a)

97

87

100

81

b)

81

100

87

97

c)

Algebra

Biology

English

History

d)

History

English

Biology

Algebra

14.

What will be the output once this code executes?

a)

97

87

100

81

b)

81

100

87

97

c)

Algebra

Biology

English

History

d)

History

English

Biology

Algebra

15.

What will be the output once this code executes?

a)

Bruce Wayne

b)

Male

c)

Gotham

d)

DC Comics

e)

Information not found

16.

What will be the output for the program above?

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

17.

What will be the output once this code executes?

a)

Bruce Wayne

b)

Male

c)

Gotham

d)

DC Comics

e)

Information not found

18.

What will be the output for the code above?

a)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]

b)

[0, 1, 2]

c)

['Python', 'Java', 'JavaScript']

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich']

19.

What will be the output for the code above?

a)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]

b)

[0, 1, 2]

c)

['Python', 'Java', 'JavaScript']

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich']

20.

What will be the output for the code above?

a)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]

b)

[0, 1, 2]

c)

['Python', 'Java', 'JavaScript']

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich']

21.

What will be the output for the code above?

a)

[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('JavaScript', 'Brendan Eich')]

b)

James Gosling

c)

['Python', 'JavaScript', 'C']

d)

['Guido Rossum', 'Brendan Eich', 'Dennis Ritchie']

22.

What will be the output for the code above?

a)

[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('JavaScript', 'Brendan Eich')]

b)

['Python', 'Java', 'JavaScript']

c)

['Guido Rossum', 'James Gosling', 'Brendan Eich']

d)

['Guido Rossum', 'Brendan Eich', 'Dennis Ritchie']

23.

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}

a)

Wolverine.get(weight)

b)

print(Wolverine.values("weight"))

c)

print(Wolverine.get("weight"))

d)

print(Wolverine.keys("weight"))

24.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

25.

Items are accessed by their index position in a dictionary

a)

True

b)

False

26.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

27.

A dictionary is ordered alphabetically by its keys

a)

true

b)

false

28.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

print(d["john"] )

a)

40

b)

45

c)

“john”

d)

“peter”

29.

6. Can you modify the value of a specific key in a dictionary in Python? If yes, how?

a)

Yes, you can modify the value of a specific key in a dictionary in Python by simply assigning a new value to that key.

b)

No, you can only add new keys to a dictionary in Python

30.

In Python, Dictionaries are immutable

a)

True

b)

False

31.

Given the dictionary d = {'spring': 'autumn', 'autumn': 'fall', 'fall': 'spring'}, what would the following code print?

print (d.get('autumn'))

a)

spring

b)

fall

c)

autumn

d)

none

32.

What will be the output for the program above?

a)

{'winter': 25, 'spring': 72, 'summer': 90}

b)

{'winter': 25, 'spring': 72, 'summer': 90, 'autumn': 60}

c)

{ }

d)

winter

33.

What will be the output for the code above?

a)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich')]

b)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]

c)

[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']

34.

Given the dictionary d = {'spring': 'autumn', 'autumn': 'fall', 'fall': 'spring'}, what would the following code print?

print (d.get('winter', "spring"))

a)

spring

b)

autumn

c)

winter

d)

fall

35.

What will be the output for the code above?

a)

['Python', 'Java', 'JavaScript', 'C']

b)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]

c)

[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']

36.

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

a)

print(len(dict1))

b)

print(dict1.get("b"))

c)

dict1["a"]=5

d)

None of these.

37.

What will be the output for the code above?

a)

['Python', 'Java', 'JavaScript', 'C']

b)

[('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ('C', 'Dennis Ritchie')]

c)

[('C', 'Dennis Ritchie'), ('Python', 'Guido Rossum'), ('Java', 'James Gosling'), ('JavaScript', 'Brendan Eich'), ]

d)

['Guido Rossum', 'James Gosling', 'Brendan Eich', 'Dennis Ritchie']

38.

Which block of code creates a key ‘age’ in dictionary D and assigns a value of 25 for this key?

a)

D={25}

b)

D = {}

D[‘age’] = 25

c)

 D = {}

D = 25

d)

none of the mentioned

39.

Given the dictionary d = {'cat': 'dog', 'dog': 'wolf', 'wolf': 'cat'}, what would the following code print?

print (d.get('lion', "cat"))

a)

cat

b)

dog

c)

lion

d)

wolf

40.

What will be the output to the console when this program executes?

a)

{'winter': 25, 'spring': 72, 'summer': 90, 'autumn': 60}

b)

0

c)

{ 0 }

d)

{ }