Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Dictionary

Total questions: 14

Worksheet time: 7mins

Name
Class
Date
1.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

2.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

3.

Items are accessed by their position in a dictionary

a)

True

b)

False

4.

Dictionary keys must be immutable

a)

True

b)

False

5.

_________________ method will not only delete the item from dictionary, but also return the deleted value.

a)

del ( )

b)

pop( )

c)

Clear( )

6.

_______________this method deletes the item from the dictionary

a)

pop( )

b)

del( )

c)

clear( )

7.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

8.

Consider this dictionary:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What is the result of this statement:


d['bar':'baz']

a)

It raises an exception

b)

(200, 300)

c)

200 300

d)

[200, 300]

9.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

10.

Which of the following cannot be a variable?

a)

__init__

b)

in

c)

it

d)

on

11.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
12.
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
13.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
14.

What would this out put? print(users[0][2])

a)

23

b)

ben

c)

sam

d)

smith