Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DICTIONARIES

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

Which of the following is not a valid way to define this dictionary in Python:

a)

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

b)

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

c)

d = dict(foo=100, bar=200, baz=300)

d)

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

e)

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

2.

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]

3.

Suppose x is defined as follows:

x = [

'a',

'b',

{

'foo': 1,

'bar':

{

'x' : 10,

'y' : 20,

'z' : 30

},

'baz': 3

},

'c',

'd'

]

What is the expression involving x that accesses the value 30?

a)

x[2]["bar"]["z"]

b)

x[2]["bar"]

c)

x["bar"]["z"]

d)

x[2]["bar"]["z"][3]

4.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

5.

Which of the following create an empty dictionary (D)?

a)

D = dict()

b)

D = ()

c)

D = []

d)

D = {}

6.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
7.

ARE THE KEYS OF A DICTIONARY BE CHANGED

a)

TRUE

b)

FALSE

8.

CAN YOU EDIT A VALUE IN A DICTIONARY?

a)

YES IT IS POSSIBLE

b)

NO IT IS NOT POSSIBLE