wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python dictionary

Total questions: 9

Worksheet time: 4mins

Name
Class
Date
1.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
2.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
3.

Given the dictionary person = {"name": "Alice", "age": 30}, how would you access Alice's age?

a)

person[age]

b)

person["Alice", "age"]

c)

person.age

d)

person["age"]

4.

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

a)

d.delete(“john”:40)

b)

d.delete(“john”)

c)

del d[“john”]

d)

del d(“john”:40)

5.

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

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

d["john"]

a)

40

b)

45

c)

“john”

d)

“peter”

6.

Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.

a)

True

b)

False

7.

Select the all correct way to remove the key ‘marks‘ from a dictionary

student = { "name": "Emma", "class": 9, "marks": 75 }

a)

student.pop(“marks”)

b)

del student[“marks”]

c)

student.popitem()

d)

dict1.remove(“key2”)

8.

What is the output of the following dictionary operation

dict1 = {"name": "Mike", "salary": 8000}

temp = dict1.get("age")

print(temp)

a)

KeyError: ‘age’

b)

None

9.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

d)

sampleDict = ()